iOS通知消息的處理

廢話不多說,直接正題!

對于通知消息的處理代理方法

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
     if(deviceToken) {

          if (![deviceToken isKindOfClass:[NSData class]])
              return;
          const unsigned *tokenBytes = [deviceToken bytes];
          NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
                                ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
                                ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
                                ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];

          [WPNotificationManager saveDeviceToken:hexToken];
      }
}

//收到遠程推送
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    NSLog(@"noti:%@",notification);
    //應(yīng)用處于后臺時的本地推送接受

}
//iOS10新增:處理前臺收到通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
    NSDictionary * userInfo = notification.request.content.userInfo;
    
    if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        //應(yīng)用處于前臺時的遠程推送接受      
    }else{
        //應(yīng)用處于前臺時的本地推送接受
 
    }
 completionHandler(UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionAlert);
}

//iOS10新增:處理后臺點擊通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
    NSDictionary * userInfo = response.notification.request.content.userInfo;
  
    if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        //應(yīng)用處于后臺時的遠程推送接受 
        
    }else{
        //應(yīng)用處于后臺時的本地推送接受

    }
    
}

上篇:本地通知消息的發(fā)送

如有瑕疵之處,望大家不吝指教

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1.ios高性能編程 (1).內(nèi)層 最小的內(nèi)層平均值和峰值(2).耗電量 高效的算法和數(shù)據(jù)結(jié)構(gòu)(3).初始化時...
    歐辰_OSR閱讀 30,194評論 8 265
  • Swift1> Swift和OC的區(qū)別1.1> Swift沒有地址/指針的概念1.2> 泛型1.3> 類型嚴謹 對...
    cosWriter閱讀 11,621評論 1 32
  • 準備早點睡的。結(jié)果接到了一個電話。 快一兩年沒聯(lián)系過了。 裹件衣服蹲在樓梯口,叼跟煙暖暖。 她說她今晚看書的時候講...
    王小賤的雜貨鋪閱讀 726評論 0 1
  • 忘記了我的阿公是哪一年出生的了,我只聽他說過,他比我阿婆要小上三歲,那個時候,流行的是“女大三抱金磚”的說法。我的...
    蘇州郁閱讀 966評論 0 7
  • 跟墨寶視頻完,郭先生關(guān)上了燈,點燃了三根蠟燭,時光荏苒,匆然間就三十歲了。。。。。 早晨睡醒,照例翻看手機,看見了...
    夢回昔日閱讀 230評論 0 0

友情鏈接更多精彩內(nèi)容