IOS8 reply processing speed for push messages

Source: Internet
Author: User
Tags notification center

IOS8 we have a new notification center and we have a new reporting mechanism. When at the top of the screen only need to receive a push-pull down, you can see the high-speed interface, talent does not need to enter the operation of the application. Lock the screen for high-speed processing to drive the project.

Push information and improve processing efficiency again.

Text messages, emails, calendars, reminders, and third-party apps that allow you to interact directly, so you can get things done quickly without going into the program and focus on what you're doing.

    • In the notification banner high-speed reply information, do not enter the SMS program;
    • You can reject or accept email invitations directly;
    • Reminders can be marked as complete or postponed;
    • When the third-party application updates the interface, it can be used directly for high-speed operation.

A recent study of the official documents of the IOS8. The function has been studied, and basically the effect has come out. Because of the cumbersome remote message push, need background support, so I use local push to replace, basically they want to invoke the proxy method similar.

Long story short, here's the main process:

1. Create a message above the action to be added (the form of a button is displayed)

Uimutableusernotificationaction *action = [[Uimutableusernotificationaction alloc] init];    Action.identifier = @ "Action";//button's logo    [email protected] "Accept";//button title    Action.activationmode = uiusernotificationactivationmodeforeground;//start the program when clicked    //    action.authenticationrequired = YES;    action.destructive = YES;    Uimutableusernotificationaction *action2 = [[Uimutableusernotificationaction alloc] init];  Second button    Action2.identifier = @ "Action2";    [Email protected] "Reject";    Action2.activationmode = uiusernotificationactivationmodebackground;//does not start the program when clicked. In the background processing    action.authenticationrequired = yes;//need to unlock talent processing, assuming action.activationmode = Uiusernotificationactivationmodeforeground; the attribute is ignored;    action.destructive = YES;

2. Create a Category collection of actions (buttons)

Uimutableusernotificationcategory *categorys = [[Uimutableusernotificationcategory alloc] init];    Categorys.identifier = @ "alert";//the only indication of this set of actions    [Categorys Setactions:@[action,action2] Forcontext: ( Uiusernotificationactioncontextminimal)];

3. Create a uiusernotificationsettings and set the display class type of the message
Uiusernotificationsettings *uns = [uiusernotificationsettings settingsfortypes: (uiusernotificationtypealert| uiusernotificationtypebadge| Uiusernotificationtypesound) Categories:[nsset Setwithobjects:categorys, Nil]];

4. Brochure Push

  [[UIApplication sharedapplication] registerusernotificationsettings:uns];<pre name= "code" class= "OBJC" >[[ UIApplication sharedapplication] registerforremotenotifications];

Userrequires call to Registerusernotificationsettings:? Silentinfo.plist uibackgroundmodes array contains remote-notification?? Can use both

Offline push packet with a specific category field (the field contents need to be defined together with the front and back tables.) Must be consistent ) when the phone is received. You can display the button that corresponds to the category setting in the above code and respond to the button event.

Payload Example: {"APS": {"alert": "Incoming", "Sound": "Default", "badge": 1, "category": "Incomingcall"}}

significant change: the data that can be brought before the offline push packet is up to a maximum of bytes , and Apple now amplifies that value to 2KB.

This is supposed to be for IOS8 only.

5. Initiating a local push message

Uilocalnotification *notification = [[Uilocalnotification alloc] init];    Notification.firedate=[nsdate Datewithtimeintervalsincenow:5];    Notification.timezone=[nstimezone Defaulttimezone];    [Email protected] "quick reply to test push";    Notification.category = @ "alert";    [[UIApplication sharedapplication]  schedulelocalnotification:notification];        Use these two methods to infer whether the register succeeds    //NSLog (@ "currentusernotificationsettings =%@", [[UIApplication sharedapplication] Currentusernotificationsettings]);    [[UIApplication sharedapplication] isregisteredforremotenotifications];

6. Dealing with results in APPDELEGATE.M

Local push notification-(void) Application: (UIApplication *) application didregisterusernotificationsettings: ( Uiusernotificationsettings *) notificationsettings{//Successful registerusernotificationsettings: After the callback method NSLog (@ "%@", notificationsettings);} -(void) Application: (UIApplication *) application didreceivelocalnotification: (uilocalnotification *) notification{/ /the Method NSLog (@ "%@", notification) called after receiving the local push message;} -(void) Application: (UIApplication *) application Handleactionwithidentifier: (NSString *) identifier Forlocalnotification: (uilocalnotification *) notification Completionhandler: (void (^) ()) completionhandler{// When you receive a local message in a non-app interface, the drop-down message will have a quick Reply button, click on the button and invoke the method, according to identifier to infer which button,notification of the click is the message content NSLog (@ "%@----%@"    , identifier,notification); Completionhandler ();//finish processing the message. Finally make sure to call this code block}//remote Push notification-(void) Application: (UIApplication *) application Didregisterforremotenotificationswithdevicetoken: (NSData *) devicetoken{//To APNs registration successful, received return of devicetoken}-(void) Application: (UIApplication *) application didFailtoregisterforremotenotificationswitherror: (Nserror *) error{//To APNs Register failed, return error message error}-(void) Application: ( UIApplication *) Application didreceiveremotenotification: (nsdictionary *) userinfo{//Receive remote push notification message}-(void) application :(uiapplication *) application Handleactionwithidentifier: (NSString *) identifier forremotenotification: ( Nsdictionary *) UserInfo Completionhandler: (void (^) ()) completionhandler{//When the app is not started. Receive the server push message. The drop-down message will have a quick Reply button, click on the button to invoke the method, according to identifier to infer which button to click}


Press SHIFT + Command +h after execution to push the program to the background, or press COMMAND+L to let the emulator lock the screen before you see the effect.

Assuming that the program is back in the background, after receiving the message, the drop-down message will appear the two buttons just added; If the lock screen is present, the left stroke will appear with the two buttons just added.

Effects such as the following:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvexvqawfueglhbmc2njy=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/southeast ">

Now just to let the message show the form of button, with the input box is still in the study, assuming the big research, but also thank you for sharing what ah. We work together to improve!

Code: Https://github.com/ios44first/PushDemo

(reprint please specify address.) Thank you http://blog.csdn.net/yujianxiang666/article/details/35260135)


IOS8 reply processing speed for push messages

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.