开发者社区> 问答> 正文

iOS API是什么?(2)



1.7 角标API




同步角标数到服务端

  • 同步设备当前角标数到推送服务端,配合角标自增功能(参考 OpenAPI 2.0 高级推送接口,搜索iOSBadgeAutoIncrement)使用;
  • SDK >= v1.9.5 支持。


参数

  • num 角标数,取值范围[0,99999]
  • callback 回调
  1. [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]void[backcolor=transparent])[backcolor=transparent]syncBadgeNum[backcolor=transparent]:([backcolor=transparent]NSUInteger[backcolor=transparent])[backcolor=transparent]num
  2. [backcolor=transparent]        withCallback[backcolor=transparent]:([backcolor=transparent]CallbackHandler[backcolor=transparent])[backcolor=transparent]callback[backcolor=transparent];



<a name=" 上报“通知点击事件”(App处于关闭状态) (Deprecated from v1.8.1)" class="reference-link" style="box-sizing: border-box; color: rgb(0, 193, 224); background: 0px 0px; transition: color 0.2s; font-weight: inherit;"> 上报“通知点击事件”(App处于关闭状态) (Deprecated from v1.8.1)

  • 上报“通知点击事件”到推送服务器;
  • 点击通知将App从关闭状态拉起时,在didFinishLaunchingWithOptions回调中调用该接口。


参数

  • launchOptions didFinishLaunchingWithOptions 回调中的launchOptions参数
  1. [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]void[backcolor=transparent])[backcolor=transparent]handleLaunching[backcolor=transparent]:([backcolor=transparent]NSDictionary[backcolor=transparent] [backcolor=transparent]*)[backcolor=transparent]launchOptions[backcolor=transparent];



<a name=" 上报“通知点击事件”(App处于打开状态) (Deprecated from v1.8.1)" class="reference-link" style="box-sizing: border-box; color: rgb(0, 193, 224); background: 0px 0px; transition: color 0.2s; font-weight: inherit;"> 上报“通知点击事件”(App处于打开状态) (Deprecated from v1.8.1)

  • 上报“通知点击事件”到推送服务器;
  • App处于打开状态(前台 or 后台),在didReceiveRemoteNotification回调中调用该接口;
  • App处于前台,通知不弹窗,直接触发回调;App处于后台,通知弹窗并触发回调。


参数

  • userInfo didReceiveRemoteNotification回调中的参数userInfo
  1. [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]void[backcolor=transparent])[backcolor=transparent]handleReceiveRemoteNotification[backcolor=transparent]:([backcolor=transparent]NSDictionary[backcolor=transparent] [backcolor=transparent]*)[backcolor=transparent]userInfo[backcolor=transparent];



2. 推送通道监听接口



2.1 监听推送通道建立

  • 通知中心注册事件名为CCPDidChannelConnectedSuccess的广播监听;
  • 推送通道成功建立后,发出事件名为CCPDidChannelConnectedSuccess的广播通知。
  1. [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]void[backcolor=transparent])[backcolor=transparent]listenerOnChannelOpened [backcolor=transparent]{
  2. [backcolor=transparent]    [backcolor=transparent][[[backcolor=transparent]NSNotificationCenter[backcolor=transparent] defaultCenter[backcolor=transparent]][backcolor=transparent] addObserver[backcolor=transparent]:[backcolor=transparent]self
  3. [backcolor=transparent]                                             selector[backcolor=transparent]:[backcolor=transparent]@selector[backcolor=transparent]([backcolor=transparent]onChannelOpened[backcolor=transparent]:)
  4. [backcolor=transparent]                                                 name[backcolor=transparent]:@[backcolor=transparent]"CCPDidChannelConnectedSuccess"
  5. [backcolor=transparent]                                               [backcolor=transparent]object[backcolor=transparent]:[backcolor=transparent]nil[backcolor=transparent]];
  6. [backcolor=transparent]}
  7. [backcolor=transparent]// 通道打开通知
  8. [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]void[backcolor=transparent])[backcolor=transparent]onChannelOpened[backcolor=transparent]:([backcolor=transparent]NSNotification[backcolor=transparent] [backcolor=transparent]*)[backcolor=transparent]notification [backcolor=transparent]{
  9. [backcolor=transparent]}



2.2 消息接收监听

  • 通知中心注册事件名为CCPDidReceiveMessageNotification的广播监听;
  • 推送通道成功建立后,发出事件名为CCPDidReceiveMessageNotification的广播通知。
  1. [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]void[backcolor=transparent])[backcolor=transparent] registerMessageReceive [backcolor=transparent]{
  2. [backcolor=transparent]    [backcolor=transparent][[[backcolor=transparent]NSNotificationCenter[backcolor=transparent] defaultCenter[backcolor=transparent]][backcolor=transparent] addObserver[backcolor=transparent]:[backcolor=transparent]self
  3. [backcolor=transparent]                                             selector[backcolor=transparent]:[backcolor=transparent]@selector[backcolor=transparent]([backcolor=transparent]onMessageReceived[backcolor=transparent]:)
  4. [backcolor=transparent]                                                 name[backcolor=transparent]:@[backcolor=transparent]"CCPDidReceiveMessageNotification"
  5. [backcolor=transparent]                                               [backcolor=transparent]object[backcolor=transparent]:[backcolor=transparent]nil[backcolor=transparent]];
  6. [backcolor=transparent]}
  7. [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]void[backcolor=transparent])[backcolor=transparent]onMessageReceived[backcolor=transparent]:([backcolor=transparent]NSNotification[backcolor=transparent] [backcolor=transparent]*)[backcolor=transparent]notification [backcolor=transparent]{
  8. [backcolor=transparent]    [backcolor=transparent]CCPSysMessage[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]message [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent][[backcolor=transparent]notification [backcolor=transparent]object[backcolor=transparent]];
  9. [backcolor=transparent]    [backcolor=transparent]NSString[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]title [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent][[[backcolor=transparent]NSString[backcolor=transparent] alloc[backcolor=transparent]][backcolor=transparent] initWithData[backcolor=transparent]:[backcolor=transparent]message[backcolor=transparent].[backcolor=transparent]title encoding[backcolor=transparent]:[backcolor=transparent]NSUTF8StringEncoding[backcolor=transparent]];
  10. [backcolor=transparent]    [backcolor=transparent]NSString[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]body [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent][[[backcolor=transparent]NSString[backcolor=transparent] alloc[backcolor=transparent]][backcolor=transparent] initWithData[backcolor=transparent]:[backcolor=transparent]message[backcolor=transparent].[backcolor=transparent]body encoding[backcolor=transparent]:[backcolor=transparent]NSUTF8StringEncoding[backcolor=transparent]];
  11. [backcolor=transparent]    [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"Receive message title: %@, content: %@."[backcolor=transparent],[backcolor=transparent] title[backcolor=transparent],[backcolor=transparent] body[backcolor=transparent]);
  12. [backcolor=transparent]}

展开
收起
猫饭先生 2017-10-23 11:08:02 1699 0
0 条回答
写回答
取消 提交回答
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载