iOS iOS8註冊通知

一直更新了iOS8,可是一直沒有開始研究這個iOS8,今天由於項目用到了推送,因而體驗了iOS8的推送,先講講這個推送。目前分爲四個推送:用戶推送,本地推送,遠程推送,地理位置推送。app

 

用戶推送ide

咱們先開始講這個用戶推送,咱們要使用以前必須先註冊這個推送,用戶要容許這個程序進行推送ui

註冊過程:spa

if (IS_IOS8) { blog

   //1.建立消息上面要添加的動做(按鈕的形式顯示出來)  it

  UIMutableUserNotificationAction *action = [[UIMutableUserNotificationAction alloc] init];  io

   action.identifier = @"action";//按鈕的標示 table

  action.title=@"Accept";//按鈕的標題  class

  action.activationMode = UIUserNotificationActivationModeForeground;//當點擊的時候啓動程序 後臺

  //    action.authenticationRequired = YES; 

  //    action.destructive = YES; 

 

   UIMutableUserNotificationAction *action2 = [[UIMutableUserNotificationAction alloc] init];  

   action2.identifier = @"action2";  

  action2.title=@"Reject";  

  action2.activationMode = UIUserNotificationActivationModeBackground;//當點擊的時候不啓動程序,在後臺處理  

  action.authenticationRequired = YES;//須要解鎖才能處理,若是action.activationMode = UIUserNotificationActivationModeForeground;則這個屬性被忽略;  

  action.destructive = YES;

           

  //2.建立動做(按鈕)的類別集合  

   UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc] init];  

  categorys.identifier = @"alert";//這組動做的惟一標示,推送通知的時候也是根據這個來區分  

  [categorys setActions:@[action,action2] forContext:(UIUserNotificationActionContextMinimal)];  

          

  //3.建立UIUserNotificationSettings,並設置消息的顯示類類型  

  UIUserNotificationSettings *notiSettings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIRemoteNotificationTypeSound) categories:[NSSet setWithObjects:categorys, nil nil]];   [application registerUserNotificationSettings:notiSettings];            

  }else{  

     [application registerForRemoteNotificationTypes: UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];

  }

 

 

 

咱們如今僅僅是註冊了通知的設置,還要註冊推送通知的行爲,在iOS8中,行爲能直接在推送消息進行,如回覆消息,拒絕消息等總結就是三個方法進行註冊

 

咱們如何能進行這些行爲,首先咱們需註冊這些行爲。

 

咱們須要注意這個UIUserNotificationActionContextDefault,若是咱們使用這個,咱們會獲得這個推送行爲,Maybe和Accept

咱們還可使用UIUserNotificationActionContextMinimal獲得的是Decline和Accept行爲

 

 

地理位置推送

這個推送是新的API纔有的特性,必須配合CLLocation定位一塊兒使用。

 

 

若是沒有開啓Core Location 那麼上面的didReceiveLocalNotification不會被調用

最後再總結一下,整個推送流程我以爲是這樣子的,先註冊推送,而後推送消息,客戶端接收推送消息,執行推送行爲。若是有錯誤,還請在文章下面評論,歡迎指正。

相關文章
相關標籤/搜索