IOS Today Extension/widget Programming Little Note

Source: Internet
Author: User

Starting with IOS8, in the "Today" dropdown, apps can add their own widgets, which is something like this:

This thing is called a widget on Android, but in iOS we call it today Extension, because it's one of the many kinds of extensions in iOS.

There are many kinds of extensions, Today extension, including share, Action, Photo Editing, Document Provider, Custom Keyboard, Watch app , some of which are familiar, like watch apps, others may not be familiar; today's main research is Extension.

First, how do I create a today extension? Very simple, in the existing project, in Xcode, choose File-new-target-application extension-today Extension, create a new Target, as shown in.

In this way, a today extension is built. Run a bit (that's the new name, an empty today Extension):

Yes, creating a today extension is so simple. For developers, a today extension is actually a somewhat special kind of uiviewcontroller; we can add subviews to this view controller, perform tasks, and so on. However, in the development process, there are some common problems:

    • How do I jump to the main app?

For today extension, the official name of the main app is called containing app;widget and there is no special way to interact with the containing app, just like any other app, calling the URL Scheme to jump to the containing app and perform some specific actions.

    • How do I determine the height and width of today extension?

For today extension, its width is immutable, the width of the screen, and its height can be changed dynamically depending on the content. Apple recommends that we use auto layout so that today's extension can adapt to its height, and if you don't use auto layout, you can call

self.preferredContentSize = CGSizeMake(0,100);

To set its height to 100;

    • How do I refresh the timer/pull-down?

Timing refresh is very simple, with Nstimer can, just pay attention to dealloc time, will nstimer destroy;

For a pull-down refresh, we'll start by figuring out which methods are called when we pull down. Just now, Today extension is actually a view Controller, so it's life cycle, is also viewdidload-viewwillappear-viewdidappear-viewwilldisappear-viewdiddisappear-dealloc this way. That is, each time the dropdown shows today extension, it will go through the process, so we just need to call the latest results in Viewdidload.

    • How do I change the name next to icon?
      The default name is the bundle name of the containing app, but we can modify the name by modifying the bundle display name in Info.plist.

Apple's suggestion for today extension: Apple believes that today extension is a place where simple operations and interfaces are simple, and there should be no complex interfaces or complex operations. So it's better not to be complicated here, otherwise you might be rejected when you submit your review.

Some areas to note:

    • The Today widget does not support keyboard input, so controls such as Uitextfield and Uitextview should not be put in.

    • In general, avoid using Uiscrollview, because today view is itself a scroll view, which can confuse the user and make it easy to operate in error.

Today extension is not a normal app, so there are some limitations:

    • Cannot use the UIApplication class;

    • Some APIs tagged with ns_extension_unavailable and some frameworks such as health kit, Event kit are not available;

    • Cannot get camera, microphone;

    • Cannot run background tasks for long periods of time;

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

The above is a general question about today's extension, and there are some high-end situations, such as increasing the refresh height of the view, determining if the extension will disappear under certain circumstances, and so on, and so on.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

IOS Today Extension/widget Programming notes

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.