IOS Today Extension/widget programming note

Source: Internet
Author: User
Tags types of extensions

IOS Today Extension/widget programming note

From iOS8, in the drop-down "today", applications can add their own widgets, which are like this:

This is called a widget in Android, but in iOS we call it Today Extension, because it is one of many types of extensions in iOS.

There are many Extensions types, including Share, Action, Photo Editing, Document Provider, Custom Keyboard, and Watch App in addition to Today Extension. Some of them are very familiar with, such as Watch App, others may be unfamiliar; Today we will mainly study Today Extension. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Watermark + 63LzytaWjrNTa0tHT0LXEz + 7Ev8Dvo6zU2lhjb2RlwO + watermark "Write picture description here" src = "http://www.bkjia.com/uploads/allimg/150903/04254S110-1.png" title = "\"/>
In this way, a Today Extension is created. Run (that is, the new name, an empty Today Extension ):

Yes, it is so easy to create a Today Extension. For developers, A Today Extension is actually a special UIViewController. We can add subviews to this View Controller to execute tasks. However, there are some common problems in the development process:

How do I jump to the main App?

For Today Extension, the official name of the main App is Containing App. widgets have no special way to interact with the Containing App. They can only be the same as other apps, call URL Scheme to jump to the ining App and perform some specific operations.

How do I determine the height and width of Today Extension?

For Today Extension, its width cannot be changed, that is, the screen width, and its height can be dynamically changed according to the content. Auto layout is recommended for apple, so that the height of Today Extension can be changed automatically. If auto layout is not required, you can call

self.preferredContentSize = CGSizeMake(0,100);

To set its height to 100;

How do I refresh the Timer/pull-down time?

Regular refresh is easy. You can use nstloc. You only need to note that nstloc is destroyed during dealloc;

For pull-down refresh, we need to first figure out which methods are called during the pull-down. As mentioned earlier, Today Extension is actually a View Controller, so its lifecycle is also the path of viewDidLoad-viewWillAppear-viewDidAppear-viewWillDisappear-viewDidDisappear-dealloc. That is to say, this process will be repeated every time the Today Extension is displayed in the drop-down list, so we only need to call the latest results in viewDidLoad.

How do I modify the name next to an Icon?
The default Name is the Bundle name of the ining App. However, you can modify this Name by modifying the Bundle display name in Info. plist.

Apple's suggestion on Today Extension: in Apple's opinion, Today Extension is a place where simple operations and interfaces are executed, and there should be no complicated interfaces or operations. Therefore, it is best not to make it complicated here, otherwise it may be rejected when it is submitted for review.

Notes:

Today widgets do not support keyboard input, so controls such as UITextField and UITextView should not be put in.

Generally, you should avoid using UIScrollView because the Today View itself is a scroll view. This will confuse users and lead to misoperations.

Today Extension is not a normal App, so there are some restrictions:

You cannot use the UIApplication class;

Some APIs marked with NS_EXTENSION_UNAVAILABLE and some frameworks such as Health Kit and Event Kit cannot be used;

You cannot obtain the camera or microphone;

You cannot run background tasks for a long time;

Data cannot be obtained through AirDrop, but data can be sent to AirDrop;

The above is a common problem about Today Extension, and there are some high-end situations, such as refreshing the height when adding the view, determining whether extension disappears under specific circumstances, and so on, further research is needed.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.