iOS8推送訊息的回複處理速度

來源:互聯網
上載者:User

標籤:

     iOS8我們有一個新的通知中樞,我們有一個新的通報機制。當在螢幕的頂部僅需要接收一個推拉向下,你可以看到高速介面,天賦並不需要輸入應用程式的操作。鎖定螢幕,用於高速處理可以推動項目。

推送資訊,再次提高處理效率。

     可以進行直接互動的簡訊、郵件、日曆、提醒,第三方應用,可以讓你不用進入程式就能進行快捷操作,並專註於手中正在做的事情。

  •  在通知橫幅高速回複資訊,不用進入簡訊程式;
  •  可直接拒絕或接受郵件邀請;
  •  可對提醒進行標記為完畢或延遲;
  •  當第三方應用程式更新介面後便可直接相應用進行高速操作。

                                        

     近期研究了下iOS8的官方文檔。對這項功能進行了鑽研,基本上效果已經出來。由於遠程訊息推送比較繁瑣,須要後台支援,所以我用本地推送來取代的,基本上它們要調用的代理方法類似。

長話短說,以下我就說下主要的流程:

1.建立訊息上面要加入的動作(button的形式顯示出來)  

 UIMutableUserNotificationAction *action = [[UIMutableUserNotificationAction alloc] init];    action.identifier = @"action";//button的標示    [email protected]"Accept";//button的標題    action.activationMode = UIUserNotificationActivationModeForeground;//當點擊的時候啟動程式    //    action.authenticationRequired = YES;    //    action.destructive = YES;    UIMutableUserNotificationAction *action2 = [[UIMutableUserNotificationAction alloc] init];  //第二button    action2.identifier = @"action2";    [email protected]"Reject";    action2.activationMode = UIUserNotificationActivationModeBackground;//當點擊的時候不啟動程式。在幕後處理    action.authenticationRequired = YES;//須要解鎖才幹處理,假設action.activationMode = UIUserNotificationActivationModeForeground;則這個屬性被忽略;    action.destructive = YES;

2.建立動作(button)的類別集合

UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc] init];    categorys.identifier = @"alert";//這組動作的唯一標示    [categorys setActions:@[action,action2] forContext:(UIUserNotificationActionContextMinimal)];

3.建立UIUserNotificationSettings,並設定訊息的顯示類類型
 UIUserNotificationSettings *uns = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound) categories:[NSSet setWithObjects:categorys, nil]];

4.注冊推送

  [[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

離線push資料包帶上特定Category欄位(欄位內容需要前後台一起定義。必需要保持一致),手機端收到時。就能展示上述代碼相應Category設定的button,和響應button事件。

// payload example:  {"aps":{"alert":"Incoming call", "sound":"default", "badge": 1, "category":"incomingCall"}}

重大改動: 離線push資料包之前能帶的資料最多為256位元組,如今APPLE將該數值放大到2KB。

這個應該是僅僅針對IOS8的。

5.發起本地推送訊息

 UILocalNotification *notification = [[UILocalNotification alloc] init];    notification.fireDate=[NSDate dateWithTimeIntervalSinceNow:5];    notification.timeZone=[NSTimeZone defaultTimeZone];    [email protected]"測試推送的快捷回複";    notification.category = @"alert";    [[UIApplication sharedApplication]  scheduleLocalNotification:notification];        //用這兩個方法推斷是否注冊成功    // NSLog(@"currentUserNotificationSettings = %@",[[UIApplication sharedApplication] currentUserNotificationSettings]);    //[[UIApplication sharedApplication] isRegisteredForRemoteNotifications];

6.在AppDelegate.m裡面對結果進行處理

//本地推播通知-(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{    //成功注冊registerUserNotificationSettings:後,回調的方法    NSLog(@"%@",notificationSettings);}-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{    //收到本地推送訊息後調用的方法    NSLog(@"%@",notification);}-(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler{    //在非本App介面時收到本地訊息,下拉訊息會有快捷回複的button,點擊button後調用的方法,依據identifier來推斷點擊的哪個button,notification為訊息內容    NSLog(@"%@----%@",identifier,notification);    completionHandler();//處理完訊息。最後一定要調用這個代碼塊}//遠程推播通知-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{    //向APNS注冊成功,收到返回的deviceToken}-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{    //向APNS注冊失敗,返回錯誤資訊error}-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{    //收到遠程推播通知訊息}-(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler{    //在沒有啟動本App時。收到server推送訊息。下拉訊息會有快捷回複的button,點擊button後調用的方法,依據identifier來推斷點擊的哪個button}


執行之後要按shift + command +H,讓程式推到後台,或者按command+L讓模擬器鎖屏,才會看到效果。

假設是程式退到後台了,收到訊息後下拉訊息,則會出現剛才加入的兩個button;假設是鎖屏了,則出現訊息後,左劃就會出現剛才加入的兩個button。

效果例如以下:

                

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveXVqaWFueGlhbmc2NjY=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" >

如今僅僅是能讓訊息中顯示出button的形式,帶輸入框的還在研究中,假設大研究了,也謝謝分享什麼啊。我們共同努力改善!

代碼:https://github.com/ios44first/PushDemo

(轉載請註明地址。謝謝 http://blog.csdn.net/yujianxiang666/article/details/35260135)


iOS8推送訊息的回複處理速度

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.