IOS8 quick reply processing for push messages

Source: Internet
Author: User
Tags vars notification center

http://blog.csdn.net/yujianxiang666/article/details/35260135

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)

[OBJC]View PlainCopy 
  1. Uimutableusernotificationaction *action = [[uimutableusernotificationaction alloc] init];
  2. Action. identifier = @ "Action"; Flag of the button
  3. Action. title=@ "Accept"; The caption of the button
  4. Action. Activationmode = Uiusernotificationactivationmodeforeground; Start the program when clicked
  5. //action.authenticationrequired = YES;
  6. //action.destructive = YES;
  7. uimutableusernotificationaction *action2 = [[Uimutableusernotificationaction alloc] init]; //second button
  8. Action2. identifier = @ "Action2";
  9. Action2. title=@ "Reject";
  10. Action2. activationmode = Uiusernotificationactivationmodebackground; Do not start the program when clicked, in the background processing
  11. Action. authenticationrequired = YES; It needs to be unlocked to process, if Action.activationmode = Uiusernotificationactivationmodeforeground, then this property is ignored;
  12. Action. Destructive = YES;

2. Create a Category collection of actions (buttons)

[OBJC]View PlainCopy 
    1. Uimutableusernotificationcategory *categorys = [[Uimutableusernotificationcategory alloc] init];
    2. Categorys. identifier = @ "alert"; The only indication of this set of actions
    3. [Categorys setactions:@[action,action2] forcontext: (Uiusernotificationactioncontextminimal)];


3. Create a uiusernotificationsettings and set the display class type of the message

[OBJC]View PlainCopy  
    1. Uiusernotificationsettings *uns = [uiusernotificationsettings settingsfortypes: (uiusernotificationtypealert| uiusernotificationtypebadge|  Uiusernotificationtypesound) categories:[nsset Setwithobjects:categorys, nil Nil]];

4. Registration push

[OBJC]View PlainCopy  
    1. [[UIApplication sharedapplication] registerusernotificationsettings:uns];
    2. <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 content needs to be defined together with the front and back table, must be consistent), when the phone receives, it can show the above code corresponding to the category Settings button, and Response button events.

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

Significant changes: The data can be brought up to 256 bytes before the offline push packet, and Apple now amplifies the value to 2KB. This is supposed to be for IOS8 only.

5. Initiating a local push message

[OBJC]View PlainCopy 
  1. Uilocalnotification *notification = [[uilocalnotification alloc] init];
  2. Notification. Firedate=[nsdate Datewithtimeintervalsincenow:5];
  3. Notification. Timezone=[nstimezone Defaulttimezone];
  4. Notification. alertbody=@ "Quick reply to test push";
  5. Notification. Category = @ "alert";
  6. [[UIApplication sharedapplication] schedulelocalnotification:notification];
  7. //Use these two methods to determine if registration is successful
  8. //NSLog (@ "currentusernotificationsettings =%@", [[UIApplication sharedapplication]  Currentusernotificationsettings]);
  9. //[[uiapplication sharedapplication] isregisteredforremotenotifications];

6. Dealing with results in APPDELEGATE.M

[OBJC]View PlainCopy 
  1. Local push Notifications
  2. -(void) application: (uiapplication *) application didregisterusernotificationsettings: ( Uiusernotificationsettings *) notificationsettings
  3. {
  4. //successfully registered Registerusernotificationsettings: After the callback method
  5. NSLog (@ "%@", notificationsettings);
  6. }
  7. -(void) application: (uiapplication *) application didreceivelocalnotification: (uilocalnotification *) Notification
  8. {
  9. //method called after local push message is received
  10. NSLog (@ "%@", notification);
  11. }
  12. -(void) application: (uiapplication *) application handleactionwithidentifier: (nsstring *) identifier forlocalnotification: (uilocalnotification *) notification Completionhandler: (void (^) ()) Completionhandler
  13. {
  14. //In the non-user interface to receive local messages, 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, notification for the message content
  15. NSLog (@ "%@----%@", identifier,notification);
  16. Completionhandler (); //Finish processing the message, and finally make sure to call this code block
  17. }
  18. Remote push Notifications
  19. -(void) application: (uiapplication *) application Didregisterforremotenotificationswithdevicetoken: ( NSData *) devicetoken
  20. {
  21. //Registered successfully with APNs, received the returned Devicetoken
  22. }
  23. -(void) application: (uiapplication *) application Didfailtoregisterforremotenotificationswitherror: ( nserror *) error
  24. {
  25. //Register failed to APNs, return error message
  26. }
  27. -(void) application: (uiapplication *) application didreceiveremotenotification: (nsdictionary *) UserInfo
  28. {
  29. //Receive remote push notification messages
  30. }
  31. -(void) application: (uiapplication *) application handleactionwithidentifier: (nsstring *) identifier  forremotenotification: (nsdictionary *) userInfo completionhandler: (void (^) ()) Completionhandler
  32. {
  33. //When the app is not launched, received the server push message, the drop-down message will have a quick Reply button, click the button after the method called, according to identifier to determine which button to click
  34. }


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)

IOS8 quick reply processing 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.