Local notifications and push notifications

Source: Internet
Author: User
Tags app service

About local notifications:

    • You must register the notification type before using the notification, and if the user does not allow the application to send notifications, you will not be able to send the notification later unless the user manually opens the notification to iOS settings.
    • Local notifications are uniformly scheduled by the operating system and can only be notified if the app exits to the background or shuts down. (Note: This is also fully applicable for subsequent push notifications.) )
    • The sound of the notification is played by the iOS system, and the format must be one of the linear PCM, MA4 (IMA/ADPCM), Μlaw, Alaw, and the playback time must be within 30s, otherwise the system sound will be replaced, and the custom sound file must be placed in main boundle.
    • The number of local notifications is limited and the nearest local notification can be up to 64, which is ignored by the system.
    • If you want to remove a local notification, you can call UIApplication's cancellocalnotification: or cancelalllocalnotifications to remove the specified notification or all notifications.

In iOS, if you tap a pop-up notification (or swipe to view notifications), the current app is automatically opened by default.

Since the notification is scheduled by the system then there are two cases of entering the application at this time:

① If the application has exited completely then it will be called at this time -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) Launchoptions method;

② if the application is still running at this time (either in the foreground or in the background) then the -(void) Application: (UIApplication *) application didreceivelocalnotification: ( Uilocalnotification *) The notification method receives the message parameter.

Of course, if the latter is naturally unnecessary to say, because the parameters can already get the notification object, just read the UserInfo property. If it is the former, you can access the Launchoptions key to the Uiapplicationlaunchoptionslocalnotificationkey object, this object is the notification sent, so that the object to access the UserInfo.

About push notifications:

Unlike local notifications, push notifications are initiated by an app service provider and sent to the app client via Apple's APNs (Apple Push Notification Server). Here's the official Apple process for push notifications:

The process of pushing notifications can be divided into the following steps:

    1. The app service provider sends messages and device tokens from the server to Apple's message-Push server APNs.
    2. APNs the device, and sends the message to the appropriate device based on the devices ' tokens on the device (IPhone, IPad, ITouch, Mac, etc.).
    3. The client device passes the received message to the appropriate application, and the application pops up the notification message based on the user settings.

1. Application registration APNS push message.

Description

A. Only registered applications are likely to receive messages, usually through UIApplication's registerusernotificationsettings: method Registration, IOS8 notification of the registration method has changed, If it is iOS7 and previous versions of iOS please refer to the other code.

B. Prior to registration there are two prerequisites that must be prepared: The app ID of the development profile (the provisioning profile, which is the . mobileprovision suffix file) cannot be used with the wildcard ID must use the specified app ID and select the Push notifications service in the build configuration file, the general development profile cannot be registered; The bundle identifier of the application must exactly match the app ID used to generate the configuration file.

2.iOS receives device token from APNs and obtains device token from the application.

Description

A. In UIApplication -(void) Application: (UIApplication *) application Didregisterforremotenotificationswithdevicetoken: (NSData *) gets the token in the Devicetoken proxy method, this method occurs after registration.

B. If the device token is not properly available in uiapplication -(void) Application: (UIApplication *) application Didfailtoregisterforremotenotificationswitherror: (Nserror *) View detailed error information in the error proxy method, which occurs after acquiring device token failed.

C. Must be debugged and the simulator cannot acquire device tokens.

The 3.iOS app sends device token to the application provider, telling the server that the current device is allowed to receive messages.

Description

A.device token generation algorithm only Apple mastered, in order to ensure that the algorithm changes will still be able to receive server-side notifications, each time the application starts to regain device token (note: Device token acquisition does not cause performance problems, Apple has been optimized by the authorities).

B. It is usually possible to create a network connection to the server side of the application provider, in which case it is best to store the last acquired device token to avoid duplication, and once the device token has changed, it is best to have the original device Token is sent to the server side, the server side deletes the original token to store the new token to avoid sending invalid messages on the server side.

4. The application provider is sent to APNs on the server side based on the device token organization information sent earlier.

Description

A. Specify device token and message content when sending, and organize message content exactly as Apple's official message format, usually with other third-party message push frameworks.

5.APNs finds registered device push messages based on device token in the message.

Description

A. Under normal circumstances, the message can be successfully pushed to the client device based on device token, but it does not preclude the user from uninstalling the program, at which point the push message fails. APNs will notify the server side of this error message to avoid wasting resources (the server can now delete the stored device token based on the error and will not send it again).

Local notifications and push notifications

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.