IOS8 quick reply processing for push messages

Source: Internet
Author: User
Tags notification center

    • 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 *)notificationSettings03.{04.//成功注册registerUserNotificationSettings:后,回调的方法05.NSLog(@"%@",notificationSettings);06.}07. 08.-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification09.{10.//收到本地推送消息后调用的方法11.NSLog(@"%@",notification);12.}13. 14.-(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler15.{16.//在非本App界面时收到本地消息,下拉消息会有快捷回复的按钮,点击按钮后调用的方法,根据identifier来判断点击的哪个按钮,notification为消息内容17.NSLog(@"%@----%@",identifier,notification);18.completionHandler();//处理完消息,最后一定要调用这个代码块19.}20. 21.//远程推送通知22.-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken23.{24.//向APNS注册成功,收到返回的deviceToken25.}26. 27.-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error28.{29.//向APNS注册失败,返回错误信息error30.}31. 32.-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo33.{34.//收到远程推送通知消息35.}36. 37.-(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler38.{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

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.