IOS8 quick reply processing for push messages

Source: Internet
Author: User

IOS8 has a new notification center with a new notification mechanism. When you receive a push at the top of the screen, you only need to pull down to see the quick-action interface, and you don't need to enter the app to operate. On the lock screen, the push item can also be processed quickly. Basically is to let the user try to do not leave the current page under the premise of processing push information, and improve processing efficiency.

The ability to interact directly with text messages, emails, calendars, reminders, and third-party apps allows you to quickly operate without getting into the program and focus on what you're doing.

    • In the notification banner quick reply information, do not enter the SMS program;
    • You can reject or accept email invitations directly;
    • Reminders can be marked for completion or delay;
    • When a third-party app updates the interface, it can quickly operate directly on the app.

Recently studied the official document of the next iOS8, the function is studied, basically the effect has come out. Because remote message push is cumbersome and requires background support, I use local push instead, basically they want to invoke the proxy method similar. Long story short, here's the basic process:

1. Create a message above the action to be added (the form of the 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;//When clicked does not start the program, in the background processing    action.authenticationrequired = yes;//need to be unlocked for processing if 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. Registration push

  [[UIApplication sharedapplication] registerforremotenotifications];    [[UIApplication sharedapplication] registerusernotificationsettings:uns];

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 determine whether the registration 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 registration 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{// In the non-user interface when the local message, the drop-down message will have a quick reply to the button, click the button after the call method, according to identifier to determine which button to click, notification for the message content NSLog (@ "%@----%@", identifier,    notification); Completionhandler ();//After processing the message, make sure to call this code block}//remote Push notification-(void) Application: (UIApplication *) application Didregisterforremotenotificationswithdevicetoken: (NSData *) devicetoken{//To APNs registered successfully, received return of devicetoken}-(void) Application: (uiapplication *) Application DidfailtoregistErforremotenotificationswitherror: (Nserror *) error{//To APNs registration 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 you do not start the app, you receive a push message from the server, the drop-down message will have a quick Reply button, click the button after the call method, According to identifier to determine which button to click}


After running to press SHIFT + command +h, to push the program to the background, or press Command+l to let the simulator lock screen, you will see the effect!

If the program is back in the background, after receiving the message, the drop-down message will appear the two buttons just added; if it is a lock screen, the left stroke will appear with the two buttons you just added.

The effect is as follows:

Now just can let the message show the form of the button, with the input box is still in the study, if you study out, also thank you can share Ah, we improve together!

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

(If you want to reprint please specify address, thank http://blog.csdn.net/yujianxiang666/article/details/35260135)


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.