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.
Quickly reply to information in the notification banner without entering the SMS program, you can directly reject or accept email invitations, you can mark reminders as complete or deferred, and when a third-party app updates the interface, you can quickly manipulate the app directly.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)
View Sourceprint?01.
UIMutableUserNotificationAction *action = [[UIMutableUserNotificationAction alloc] init];
02.
action.identifier = @
"action"
;
//按钮的标示
03.
[email protected]
"Accept"
;
//按钮的标题
04.
action.activationMode = UIUserNotificationActivationModeForeground;
//当点击的时候启动程序
05.
// action.authenticationRequired = YES;
06.
// action.destructive = YES;
07.
08.
UIMutableUserNotificationAction *action2 = [[UIMutableUserNotificationAction alloc] init];
//第二按钮
09.
action2.identifier = @
"action2"
;
10.
[email protected]
"Reject"
;
11.
action2.activationMode = UIUserNotificationActivationModeBackground;
//当点击的时候不启动程序,在后台处理
12.
action.authenticationRequired = YES;
//需要解锁才能处理,如果action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略;
13.
action.destructive = YES;
2. Create a Category collection of actions (buttons)
View Sourceprint?1.
UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc] init];
2.
categorys.identifier = @
"alert"
;
//这组动作的唯一标示
3.
[categorys setActions:@[action,action2] forContext:(UIUserNotificationActionContextMinimal)];
3. Create a uiusernotificationsettings and set the display class type of the message
View Sourceprint?1.
UIUserNotificationSettings *uns = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound) categories:[NSSet setWithObjects:categorys, nil]];
4. Registration push
View Sourceprint?1.
[[UIApplication sharedApplication] registerForRemoteNotifications];
2.
[[UIApplication sharedApplication] registerUserNotificationSettings:uns];
5. Initiating a local push message
View Sourceprint?01.
UILocalNotification *notification = [[UILocalNotification alloc] init];
02.
notification.fireDate=[NSDate dateWithTimeIntervalSinceNow:
5
];
03.
notification.timeZone=[NSTimeZone defaultTimeZone];
04.
[email protected]
"测试推送的快捷回复"
;
05.
notification.category = @
"alert"
;
06.
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
07.
08.
//用这两个方法判断是否注册成功
09.
// NSLog(@"currentUserNotificationSettings = %@",[[UIApplication sharedApplication] currentUserNotificationSettings]);
10.
//[[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
6. Dealing with results in APPDELEGATE.M
View Sourceprint?01.
//本地推送通知
02.
-(
void
)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
03.
{
04.
//成功注册registerUserNotificationSettings:后,回调的方法
05.
NSLog(@
"%@"
,notificationSettings);
06.
}
07.
08.
-(
void
)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
09.
{
10.
//收到本地推送消息后调用的方法
11.
NSLog(@
"%@"
,notification);
12.
}
13.
14.
-(
void
)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(
void
(^)())completionHandler
15.
{
16.
//在非本App界面时收到本地消息,下拉消息会有快捷回复的按钮,点击按钮后调用的方法,根据identifier来判断点击的哪个按钮,notification为消息内容
17.
NSLog(@
"%@----%@"
,identifier,notification);
18.
completionHandler();
//处理完消息,最后一定要调用这个代码块
19.
}
20.
21.
//远程推送通知
22.
-(
void
)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
23.
{
24.
//向APNS注册成功,收到返回的deviceToken
25.
}
26.
27.
-(
void
)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
28.
{
29.
//向APNS注册失败,返回错误信息error
30.
}
31.
32.
-(
void
)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
33.
{
34.
//收到远程推送通知消息
35.
}
36.
37.
-(
void
)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(
void
(^)())completionHandler
38.
{
39.
//在没有启动本App时,收到服务器推送消息,下拉消息会有快捷回复的按钮,点击按钮后调用的方法,根据identifier来判断点击的哪个按钮
40.
}
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
Address, thank you http://blog.csdn.net/yujianxiang666/article/details/35260135