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
- Uimutableusernotificationaction *action = [[uimutableusernotificationaction alloc] init];
- Action. identifier = @ "Action"; Flag of the button
- Action. title=@ "Accept"; The caption of the button
- Action. Activationmode = Uiusernotificationactivationmodeforeground; Start the program when clicked
- //action.authenticationrequired = YES;
- //action.destructive = YES;
- uimutableusernotificationaction *action2 = [[Uimutableusernotificationaction alloc] init]; //second button
- Action2. identifier = @ "Action2";
- Action2. title=@ "Reject";
- Action2. activationmode = Uiusernotificationactivationmodebackground; Do not start the program when clicked, in the background processing
- Action. authenticationrequired = YES; It needs to be unlocked to process, if Action.activationmode = Uiusernotificationactivationmodeforeground, then this property is ignored;
- Action. Destructive = YES;
2. Create a Category collection of actions (buttons)
[OBJC]View PlainCopy
- 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
[OBJC]View PlainCopy
- Uiusernotificationsettings *uns = [uiusernotificationsettings settingsfortypes: (uiusernotificationtypealert| uiusernotificationtypebadge| Uiusernotificationtypesound) categories:[nsset Setwithobjects:categorys, nil Nil]];
4. Registration push
[OBJC]View PlainCopy
- [[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 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
- Uilocalnotification *notification = [[uilocalnotification alloc] init];
- Notification. Firedate=[nsdate Datewithtimeintervalsincenow:5];
- Notification. Timezone=[nstimezone Defaulttimezone];
- Notification. alertbody=@ "Quick reply to test push";
- Notification. Category = @ "alert";
- [[UIApplication sharedapplication] schedulelocalnotification:notification];
- //Use these two methods to determine if registration is successful
- //NSLog (@ "currentusernotificationsettings =%@", [[UIApplication sharedapplication] Currentusernotificationsettings]);
- //[[uiapplication sharedapplication] isregisteredforremotenotifications];
6. Dealing with results in APPDELEGATE.M
[OBJC]View PlainCopy
- Local push Notifications
- -(void) application: (uiapplication *) application didregisterusernotificationsettings: ( Uiusernotificationsettings *) notificationsettings
- {
- //successfully registered Registerusernotificationsettings: After the callback method
- NSLog (@ "%@", notificationsettings);
- }
- -(void) application: (uiapplication *) application didreceivelocalnotification: (uilocalnotification *) Notification
- {
- //method called after local push message is received
- NSLog (@ "%@", notification);
- }
- -(void) application: (uiapplication *) application handleactionwithidentifier: (nsstring *) identifier forlocalnotification: (uilocalnotification *) notification Completionhandler: (void (^) ()) Completionhandler
- {
- //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
- NSLog (@ "%@----%@", identifier,notification);
- Completionhandler (); //Finish processing the message, and finally make sure to call this code block
- }
- Remote push Notifications
- -(void) application: (uiapplication *) application Didregisterforremotenotificationswithdevicetoken: ( NSData *) devicetoken
- {
- //Registered successfully with APNs, received the returned Devicetoken
- }
- -(void) application: (uiapplication *) application Didfailtoregisterforremotenotificationswitherror: ( nserror *) error
- {
- //Register failed to APNs, return error message
- }
- -(void) application: (uiapplication *) application didreceiveremotenotification: (nsdictionary *) UserInfo
- {
- //Receive remote push notification messages
- }
- -(void) application: (uiapplication *) application handleactionwithidentifier: (nsstring *) identifier forremotenotification: (nsdictionary *) userInfo completionhandler: (void (^) ()) Completionhandler
- {
- //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
- }
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