Research on the latest features of ios10 push

Recently, I have made great changes in the research on the new push features of ios10 compared with the previous ones. To sum up, the main points are as follows:

1. Push more content, from the previous alert to the current title, subtitle, body 2 Push unified triggered by trigger 3 You can add attachments to push, such as pictures, audio and video, which makes the push content more colorful 4 Push content can be easily updated

Import new framework

Add a new framework usernotifications framework

#import

Registration push

When setting notifications, you need to register first to obtain authorization. All notifications of ios10 are managed through the unusernotification center, including remote notifications and local notifications

Get user settings

Ios10 provides an interface getnotificationsettingswithcompletionhandler for obtaining user authorization related setting information. The callback has an unnotificationsettings object, which has the following properties to accurately obtain various authorization information

authorizationStatus soundSetting badgeSetting alertSetting notificationCenterSetting lockScreenSetting carPlaySetting alertStyle

Like the following method, click allow

Print information: * < unnotificationsettings: 0x174090a90; authorizationStatus: Authorized,notificationCenterSetting: Enabled,soundSetting: Enabled,badgeSetting: Enabled,lockScreenSetting: Enabled,alertSetting: NotSupported,carPlaySetting: Enabled,alertStyle: Banner>*

Register APNs and get token

Ios10, the method of registering APNs and obtaining token is the same as before. In application: didfinishlaunchingwithoptions: call the registerforremotenotifications method [[uiapplication sharedapplication] registerforremotenotifications];

Get token in proxy method application: didregisterforremotenotificationswithdevicetoken:

Set the action and category for handling notifications

Before ios8, there was no Category attribute; When registering push and obtaining authorization in ios8, you can set category together. The registered method directly carries this parameter; In ios10, you need to call a method setnotificationcategories: to set category for the instance of unusernotificationcenter that manages push, and category can set action accordingly;

Set notification content

Because ios10 remote notification and local notification are unified, the notification content properties are consistent, but remote push needs to be specifically set on the payload. Next, take local notification as an example to introduce the content of unnotificationcontent. It is clearly explained on the official website that we cannot directly create an instance of unnotificationcontent, If we need to configure the properties of the content ourselves, We need to use unmutablenotificationcontent to see some of its properties: attachments / / attachment BADGE / / logo body / / push content body categoryidentifier / / category ID launchinginame / / click the notification to enter the startup diagram of the application sound / / sound subtitle / / push content subtitle / / push content title userinfo / / remote notification content

Notification trigger

There are 4 types of unnotificationtrigger IOS 10 triggers • unpushnotificationtrigger triggers APNs service, Automatically set by the system (this is the identification to distinguish between local notification and remote notification) • untimeintervalnotificationtrigger will be triggered after a period of time • uncalendarnotificationtrigger will be triggered on a specified date • unloocationnotificationtrigger will be triggered according to the location. It supports entering a place or leaving a place or both

Add / update notifications

1. To create an instance of unnotificationrequest class, you must set an identifier for it to find, update and delete notifications later. This identifier can be used to distinguish this notification from other notifications. 2 Add the request to the unusernotification center, set the trigger, and wait for the trigger 3 If another request has the same ID and different content as the previous request, the purpose of updating the notification can be achieved

Get and delete notifications

There are two statuses for notifications here • pending notifications waiting to be triggered • delivered notifications that have been triggered and displayed in the notification center

delegate

Ios10 no longer processes notifications in the application: didreceiveremotenotification: method. Ios10 introduces a new proxy method to receive and process all kinds of notifications (local or remote)

last

The next article will continue to introduce the unnotificationserviceextension and notification content extension of rich media push, which will be continued...

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>