iOS API是什么?(3)
2.3 通知打开监听
iOS 10+
- [backcolor=transparent]/**
- [backcolor=transparent] * 处理iOS 10通知(iOS 10+)
- [backcolor=transparent] */
- [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]void[backcolor=transparent])[backcolor=transparent]handleiOS10Notification[backcolor=transparent]:([backcolor=transparent]UNNotification[backcolor=transparent] [backcolor=transparent]*)[backcolor=transparent]notification [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]UNNotificationRequest[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]request [backcolor=transparent]=[backcolor=transparent] notification[backcolor=transparent].[backcolor=transparent]request[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]UNNotificationContent[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]content [backcolor=transparent]=[backcolor=transparent] request[backcolor=transparent].[backcolor=transparent]content[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]NSDictionary[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]userInfo [backcolor=transparent]=[backcolor=transparent] content[backcolor=transparent].[backcolor=transparent]userInfo[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]// 通知时间
- [backcolor=transparent] [backcolor=transparent]NSDate[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]noticeDate [backcolor=transparent]=[backcolor=transparent] notification[backcolor=transparent].[backcolor=transparent]date[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]// 标题
- [backcolor=transparent] [backcolor=transparent]NSString[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]title [backcolor=transparent]=[backcolor=transparent] content[backcolor=transparent].[backcolor=transparent]title[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]// 副标题
- [backcolor=transparent] [backcolor=transparent]NSString[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]subtitle [backcolor=transparent]=[backcolor=transparent] content[backcolor=transparent].[backcolor=transparent]subtitle[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]// 内容
- [backcolor=transparent] [backcolor=transparent]NSString[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]body [backcolor=transparent]=[backcolor=transparent] content[backcolor=transparent].[backcolor=transparent]body[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]// 角标
- [backcolor=transparent] [backcolor=transparent]int[backcolor=transparent] badge [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent][[backcolor=transparent]content[backcolor=transparent].[backcolor=transparent]badge intValue[backcolor=transparent]];
- [backcolor=transparent] [backcolor=transparent]// 取得通知自定义字段内容,例:获取key为"Extras"的内容
- [backcolor=transparent] [backcolor=transparent]NSString[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]extras [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent][[backcolor=transparent]userInfo valueForKey[backcolor=transparent]:@[backcolor=transparent]"Extras"[backcolor=transparent]];
- [backcolor=transparent] [backcolor=transparent]// 通知打开回执上报
- [backcolor=transparent] [backcolor=transparent][[backcolor=transparent]CloudPushSDK[backcolor=transparent] sendNotificationAck[backcolor=transparent]:[backcolor=transparent]userInfo[backcolor=transparent]];
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"Notification, date: %@, title: %@, subtitle: %@, body: %@, badge: %d, extras: %@."[backcolor=transparent],[backcolor=transparent] noticeDate[backcolor=transparent],[backcolor=transparent] title[backcolor=transparent],[backcolor=transparent] subtitle[backcolor=transparent],[backcolor=transparent] body[backcolor=transparent],[backcolor=transparent] badge[backcolor=transparent],[backcolor=transparent] extras[backcolor=transparent]);
- [backcolor=transparent]}
- [backcolor=transparent]/**
- [backcolor=transparent] * App处于前台时收到通知(iOS 10+)
- [backcolor=transparent] */
- [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]void[backcolor=transparent])[backcolor=transparent]userNotificationCenter[backcolor=transparent]:([backcolor=transparent]UNUserNotificationCenter[backcolor=transparent] [backcolor=transparent]*)[backcolor=transparent]center willPresentNotification[backcolor=transparent]:([backcolor=transparent]UNNotification[backcolor=transparent] [backcolor=transparent]*)[backcolor=transparent]notification withCompletionHandler[backcolor=transparent]:([backcolor=transparent]void[backcolor=transparent] [backcolor=transparent](^)([backcolor=transparent]UNNotificationPresentationOptions[backcolor=transparent]))[backcolor=transparent]completionHandler [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"Receive a notification in foregound."[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]// 处理iOS 10通知相关字段信息
- [backcolor=transparent] [backcolor=transparent][[backcolor=transparent]self[backcolor=transparent] handleiOS10Notification[backcolor=transparent]:[backcolor=transparent]notification[backcolor=transparent]];
- [backcolor=transparent] [backcolor=transparent]// 通知不弹出
- [backcolor=transparent] [backcolor=transparent]//completionHandler(UNNotificationPresentationOptionNone);
- [backcolor=transparent] [backcolor=transparent]// 通知弹出,且带有声音、内容和角标(App处于前台时不建议弹出通知)
- [backcolor=transparent] completionHandler[backcolor=transparent]([backcolor=transparent]UNNotificationPresentationOptionSound[backcolor=transparent] [backcolor=transparent]|[backcolor=transparent] [backcolor=transparent]UNNotificationPresentationOptionAlert[backcolor=transparent] [backcolor=transparent]|[backcolor=transparent] [backcolor=transparent]UNNotificationPresentationOptionBadge[backcolor=transparent]);
- [backcolor=transparent]}
- 触发通知动作时回调,比如点击、删除通知和点击自定义action(iOS 10+);
- [backcolor=transparent]/**
- [backcolor=transparent] * 触发通知动作时回调,比如点击、删除通知和点击自定义action(iOS 10+)
- [backcolor=transparent] */
- [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]void[backcolor=transparent])[backcolor=transparent]userNotificationCenter[backcolor=transparent]:([backcolor=transparent]UNUserNotificationCenter[backcolor=transparent] [backcolor=transparent]*)[backcolor=transparent]center didReceiveNotificationResponse[backcolor=transparent]:([backcolor=transparent]UNNotificationResponse[backcolor=transparent] [backcolor=transparent]*)[backcolor=transparent]response withCompletionHandler[backcolor=transparent]:([backcolor=transparent]void[backcolor=transparent] [backcolor=transparent](^)())[backcolor=transparent]completionHandler [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]NSString[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]userAction [backcolor=transparent]=[backcolor=transparent] response[backcolor=transparent].[backcolor=transparent]actionIdentifier[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]// 点击通知打开
- [backcolor=transparent] [backcolor=transparent]if[backcolor=transparent] [backcolor=transparent]([[backcolor=transparent]userAction isEqualToString[backcolor=transparent]:[backcolor=transparent]UNNotificationDefaultActionIdentifier[backcolor=transparent]])[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"User opened the notification."[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]// 处理iOS 10通知,并上报通知打开回执
- [backcolor=transparent] [backcolor=transparent][[backcolor=transparent]self[backcolor=transparent] handleiOS10Notification[backcolor=transparent]:[backcolor=transparent]response[backcolor=transparent].[backcolor=transparent]notification[backcolor=transparent]];
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent] [backcolor=transparent]// 通知dismiss,category创建时传入UNNotificationCategoryOptionCustomDismissAction才可以触发
- [backcolor=transparent] [backcolor=transparent]if[backcolor=transparent] [backcolor=transparent]([[backcolor=transparent]userAction isEqualToString[backcolor=transparent]:[backcolor=transparent]UNNotificationDismissActionIdentifier[backcolor=transparent]])[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"User dismissed the notification."[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent] [backcolor=transparent]NSString[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]customAction1 [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]@[backcolor=transparent]"action1"[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]NSString[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]customAction2 [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]@[backcolor=transparent]"action2"[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]// 点击用户自定义Action1
- [backcolor=transparent] [backcolor=transparent]if[backcolor=transparent] [backcolor=transparent]([[backcolor=transparent]userAction isEqualToString[backcolor=transparent]:[backcolor=transparent]customAction1[backcolor=transparent]])[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"User custom action1."[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent] [backcolor=transparent]// 点击用户自定义Action2
- [backcolor=transparent] [backcolor=transparent]if[backcolor=transparent] [backcolor=transparent]([[backcolor=transparent]userAction isEqualToString[backcolor=transparent]:[backcolor=transparent]customAction2[backcolor=transparent]])[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"User custom action2."[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent] completionHandler[backcolor=transparent]();
- [backcolor=transparent]}
iOS 10以下版本
- [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]BOOL[backcolor=transparent])[backcolor=transparent]application[backcolor=transparent]:([backcolor=transparent]UIApplication[backcolor=transparent] [backcolor=transparent]*)[backcolor=transparent]application didFinishLaunchingWithOptions[backcolor=transparent]:([backcolor=transparent]NSDictionary[backcolor=transparent] [backcolor=transparent]*)[backcolor=transparent]launchOptions [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]// 点击通知将App从关闭状态启动时,将通知打开回执上报
- [backcolor=transparent] [backcolor=transparent]// [CloudPushSDK handleLaunching:launchOptions];(Deprecated from v1.8.1)
- [backcolor=transparent] [backcolor=transparent][[backcolor=transparent]CloudPushSDK[backcolor=transparent] sendNotificationAck[backcolor=transparent]:[backcolor=transparent]launchOptions[backcolor=transparent]];
- [backcolor=transparent] [backcolor=transparent]return[backcolor=transparent] YES[backcolor=transparent];
- [backcolor=transparent]}
- [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]void[backcolor=transparent])[backcolor=transparent]application[backcolor=transparent]:([backcolor=transparent]UIApplication[backcolor=transparent]*)[backcolor=transparent]application didReceiveRemoteNotification[backcolor=transparent]:([backcolor=transparent]NSDictionary[backcolor=transparent]*)[backcolor=transparent]userInfo [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"Receive one notification."[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]// 取得APNS通知内容
- [backcolor=transparent] [backcolor=transparent]NSDictionary[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]aps [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent][[backcolor=transparent]userInfo valueForKey[backcolor=transparent]:@[backcolor=transparent]"aps"[backcolor=transparent]];
- [backcolor=transparent] [backcolor=transparent]// 内容
- [backcolor=transparent] [backcolor=transparent]NSString[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]content [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent][[backcolor=transparent]aps valueForKey[backcolor=transparent]:@[backcolor=transparent]"alert"[backcolor=transparent]];
- [backcolor=transparent] [backcolor=transparent]// badge数量
- [backcolor=transparent] [backcolor=transparent]NSInteger[backcolor=transparent] badge [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent][[[backcolor=transparent]aps valueForKey[backcolor=transparent]:@[backcolor=transparent]"badge"[backcolor=transparent]][backcolor=transparent] integerValue[backcolor=transparent]];
- [backcolor=transparent] [backcolor=transparent]// 播放声音
- [backcolor=transparent] [backcolor=transparent]NSString[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]sound [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent][[backcolor=transparent]aps valueForKey[backcolor=transparent]:@[backcolor=transparent]"sound"[backcolor=transparent]];
- [backcolor=transparent] [backcolor=transparent]// 取得Extras字段内容
- [backcolor=transparent] [backcolor=transparent]NSString[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]Extras[backcolor=transparent] [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent][[backcolor=transparent]userInfo valueForKey[backcolor=transparent]:@[backcolor=transparent]"Extras"[backcolor=transparent]];[backcolor=transparent] [backcolor=transparent]//服务端中Extras字段,key是自己定义的
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"content = [%@], badge = [%ld], sound = [%@], Extras = [%@]"[backcolor=transparent],[backcolor=transparent] content[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]long[backcolor=transparent])[backcolor=transparent]badge[backcolor=transparent],[backcolor=transparent] sound[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]Extras[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]// iOS badge 清0
- [backcolor=transparent] application[backcolor=transparent].[backcolor=transparent]applicationIconBadgeNumber [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]0[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]// 通知打开回执上报
- [backcolor=transparent] [backcolor=transparent]// [CloudPushSDK handleReceiveRemoteNotification:userInfo];(Deprecated from v1.8.1)
- [backcolor=transparent] [backcolor=transparent][[backcolor=transparent]CloudPushSDK[backcolor=transparent] sendNotificationAck[backcolor=transparent]:[backcolor=transparent]userInfo[backcolor=transparent]];
- [backcolor=transparent]}
收起
猫饭先生
2017-10-23 11:08:25
1328
0
0
条回答
写回答
取消
提交回答