極光推送

上報推送 ID

為了保证登錄之後的用户也能设置 registrationID 属性,需要在 - registrationIDCompletionHandler: 回调和调用神策 - login: 接口之後,各上報一次 registrationID

// 神策 SDK 初始化之後,在极光回调中上報 registrationID
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="6461343d-3293-4f84-ab6f-0bfb78e215d4"><ac:plain-text-body><![CDATA[[JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
]]></ac:plain-text-body></ac:structured-macro>
// 將 registrationID 保存到神策用户表的 jiguang_id 字段中(这⾥的 jiguang_id 只是一个示例字段)
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="0afd96f9-6baf-43f9-b92a-2c6cd791b91f"><ac:plain-text-body><![CDATA[ [[SensorsAnalyticsSDK sharedInstance] set:@"jiguang_id" to:registrationID];
]]></ac:plain-text-body></ac:structured-macro>
}];

// login 之後,再次上報 registrationID
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="f0c5ee3d-7b99-4875-b7e8-f5eed7630f0f"><ac:plain-text-body><![CDATA[[[SensorsAnalyticsSDK sharedInstance] login:<#登錄 ID#>];
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="7da3fa6c-7fc2-492c-911c-fb1f4ddcd3ff"><ac:plain-text-body><![CDATA[[[SensorsAnalyticsSDK sharedInstance] set:@"jiguang_id" to:registrationID];

]]></ac:plain-text-body></ac:structured-macro>


采集推送點擊事件

神策 iOS SDK 可以自動采集来自极光的推送點擊事件,請参考文档開启采集。

處理平台推送的消息

// iOS10以下,點擊通知的回调

  • (<span style="color: #336699"><strong>void</strong></span>)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler<span style="color: #336699"><strong>void</strong></span> (^)(UIBackgroundFetchResult))completionHandler {

    <span style="color: #008200">// Required, iOS 7 Support</span>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ab969836-c319-4d0a-b369-94f0cb440334"><ac:plain-text-body><![CDATA[ [JPUSHService handleRemoteNotification:userInfo];
    ]]></ac:plain-text-body></ac:structured-macro>
    <span style="color: #008200">// 處理平台推送的消息</span>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="64ee38a8-6498-4237-9a62-9933b631517d"><ac:plain-text-body><![CDATA[ [SensorsFocusHelper dealSensorsFocusAction:userInfo link:^(NSString * _Nonnull urlString) {
    ]]></ac:plain-text-body></ac:structured-macro>
    <span style="color: #008200">// TODO 處理打開 URL 消息,--> 請處理 URL</span>
    } customize:^(NSDictionary * _Nonnull customizedDic) {
    <span style="color: #008200">// TODO 處理自定義消息,--> 請處理自定義消息</span>
    }];
    completionHandler(UIBackgroundFetchResultNewData);
    }

    <span style="color: #008200">// iOS10以上,點擊通知的回调</span>

  • (<span style="color: #336699"><strong>void</strong></span>)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler<span style="color: #336699"><strong>void</strong></span>(^)(<span style="color: #336699"><strong>void</strong></span>))completionHandler API_AVAILABLE(ios(<span style="color: #009900">10.0</span>)){
    <span style="color: #008200">// Required</span>
    NSDictionary *userInfo = response.notification.request.content.userInfo;
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8dc07973-7b33-4d62-8a01-12f4023e9374"><ac:plain-text-body><![CDATA[ <span style="color: #336699"><strong>if</strong></span> ([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger <span style="color: #336699"><strong>class</strong></span>]]) {
    ]]></ac:plain-text-body></ac:structured-macro>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="84020fdf-b7e9-43a7-aac5-fba036545226"><ac:plain-text-body><![CDATA[ [JPUSHService handleRemoteNotification:userInfo];
    ]]></ac:plain-text-body></ac:structured-macro>
    }

    <span style="color: #008200">// 處理平台推送的消息</span>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d5ce0d46-b449-4956-95d2-222cc3686214"><ac:plain-text-body><![CDATA[ [SensorsFocusHelper dealSensorsFocusAction:userInfo link:^(NSString * _Nonnull urlString) {
    ]]></ac:plain-text-body></ac:structured-macro>
    <span style="color: #008200">// TODO 處理打開 URL 消息,--> 請處理 URL</span>
    } customize:^(NSDictionary * _Nonnull customizedDic) {
    <span style="color: #008200">// TODO 處理自定義消息,--> 請處理自定義消息</span>
    }];
    completionHandler(); <span style="color: #008200">// 系统要求執行这个方法</span>
    }


友盟推送

上報 deviceToken

為了保证登錄之後的用户也能设置 deviceToken 属性,需要在获取到 deviceToken 時和调用神策 -login:  接口之後,各上報一次 deviceToken

/** 遠程通知注册成功委托 */

  • (<span style="color: #336699"><strong>void</strong></span>)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="cb638748-9b42-43d5-9487-ab743967960a"><ac:plain-text-body><![CDATA[ [UMessage registerDeviceToken:deviceToken];
    ]]></ac:plain-text-body></ac:structured-macro>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ef0f0a81-d745-4669-be67-00c7ecb4b661"><ac:plain-text-body><Unable to render embedded object: File ( #336699"><strong>if</strong></span> () not found.[deviceToken isKindOfClass:[NSData <span style="color: #336699"><strong>class</strong></span>]]) <span style="color: #336699"><strong>return</strong></span>;
    ]]></ac:plain-text-body></ac:structured-macro>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="544fc20b-a978-42e8-8f2d-c6690d2864d1"><ac:plain-text-body><![CDATA[ <span style="color: #336699"><strong>const</strong></span> unsigned *tokenBytes = (<span style="color: #336699"><strong>const</strong></span> unsigned *)[deviceToken bytes];
    ]]></ac:plain-text-body></ac:structured-macro>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="26997846-07f5-4a3f-9bf0-9f41ba84ca07"><ac:plain-text-body><![CDATA[ NSString *hexToken = [NSString stringWithFormat:@<span style="color: #003366">"%08x%08x%08x%08x%08x%08x%08x%08x"</span>,
    ]]></ac:plain-text-body></ac:structured-macro>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="6015b753-870c-4c7e-a94e-f5316eacc546"><ac:plain-text-body><![CDATA[ ntohl(tokenBytes[<span style="color: #009900">0</span>]), ntohl(tokenBytes[<span style="color: #009900">1</span>]), ntohl(tokenBytes[<span style="color: #009900">2</span>]),
    ]]></ac:plain-text-body></ac:structured-macro>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="63b5f4d7-e2a7-42d5-a2b1-090ede6c7023"><ac:plain-text-body><![CDATA[ ntohl(tokenBytes[<span style="color: #009900">3</span>]), ntohl(tokenBytes[<span style="color: #009900">4</span>]), ntohl(tokenBytes[<span style="color: #009900">5</span>]),
    ]]></ac:plain-text-body></ac:structured-macro>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="b5685668-f3bc-42c0-9898-59db5fbde3d7"><ac:plain-text-body><![CDATA[ ntohl(tokenBytes[<span style="color: #009900">6</span>]), ntohl(tokenBytes[<span style="color: #009900">7</span>])];
    ]]></ac:plain-text-body></ac:structured-macro>
    <span style="color: #008200">// 將 deviceToken 保存到神策用户表 umeng_id 中(这里的 umeng_id 只是一个示例字段)</span>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="691c0525-539f-4549-a0f6-d4f5ebdafb79"><ac:plain-text-body><![CDATA[ [[SensorsAnalyticsSDK sharedInstance] set:@<span style="color: #003366">"umeng_id"</span> to:hexToken];
    ]]></ac:plain-text-body></ac:structured-macro>
    <span style="color: #808080">/**</span>
    <span style="color: #808080">* 將 hexToken 進行缓存</span>
    <span style="color: #808080">*/</span>
    }

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="1914e2bb-a248-4315-8e98-f4edeba65478"><ac:plain-text-body><![CDATA[

[[SensorsAnalyticsSDK sharedInstance] login:<#登錄 ID#>];
]]></ac:plain-text-body></ac:structured-macro>
 
// 為了保证登錄後的用户也能正确设置 deviceToken,调用 login 之後,需要再次上報。
NSString *hexToken = <#取出之前缓存的 hexToken#>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="677951d9-fcff-4216-81ea-4b080f8ebf9e"><ac:plain-text-body><![CDATA[[[SensorsAnalyticsSDK sharedInstance] set:@"umeng_id" to:hexToken];

]]></ac:plain-text-body></ac:structured-macro>


記錄 「推送打開」事件并處理智能运营平台推送的消息

// iOS10 一下版本,iOS 7 Support

  • (<span style="color: #336699"><strong>void</strong></span>)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler<span style="color: #336699"><strong>void</strong></span> (^)(UIBackgroundFetchResult))completionHandler {
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="3b81ab18-4ecd-48fd-acfe-116d5d024d8a"><ac:plain-text-body><![CDATA[ [UMessage didReceiveRemoteNotification:userInfo];
    ]]></ac:plain-text-body></ac:structured-macro>
    <span style="color: #008200">// 記錄 推送打開 事件</span>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="868348cd-1766-4513-bc69-b1e0b8520143"><ac:plain-text-body><![CDATA[ [SensorsFocusHelper trackSensorsFocusAppOpenNotificationWithUserInfo:userInfo];
    ]]></ac:plain-text-body></ac:structured-macro>
    <span style="color: #008200">// 處理平台推送的消息</span>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="94fc616f-1c72-40ad-ade6-2a4297988709"><ac:plain-text-body><![CDATA[ [SensorsFocusHelper dealSensorsFocusAction:userInfo link:^(NSString * _Nonnull urlString) {
    ]]></ac:plain-text-body></ac:structured-macro>
    <span style="color: #008200">// TODO 處理打開 URL 消息,--> 請處理 URL</span>
    } customize:^(NSDictionary * _Nonnull customizedDic) {
    <span style="color: #008200">// TODO 處理自定義消息,--> 請處理自定義消息</span>
    }];
    completionHandler(UIBackgroundFetchResultNewData);
    }

    <span style="color: #008200">// iOS 10: 點擊通知進入App時觸發,在该方法内统计有效用户點擊數</span>

  • (<span style="color: #336699"><strong>void</strong></span>)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler<span style="color: #336699"><strong>void</strong></span> (^)())completionHandler {

    NSDictionary *userInfo = response.notification.request.content.userInfo;
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="77210dde-5e04-4fec-b79f-385342645fe8"><ac:plain-text-body><![CDATA[ <span style="color: #336699"><strong>if</strong></span> ([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger <span style="color: #336699"><strong>class</strong></span>]]) {
    ]]></ac:plain-text-body></ac:structured-macro>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="fac93186-fe3f-40e6-8662-369bbf865a8f"><ac:plain-text-body><![CDATA[ [UMessage didReceiveRemoteNotification:userInfo];
    ]]></ac:plain-text-body></ac:structured-macro>
    }

    <span style="color: #008200">// 記錄 推送打開 事件</span>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d1b23c73-d8ea-4226-8f5c-3c16b0d69eb8"><ac:plain-text-body><![CDATA[ [SensorsFocusHelper trackSensorsFocusAppOpenNotificationWithUserInfo:userInfo];
    ]]></ac:plain-text-body></ac:structured-macro>
    <span style="color: #008200">// 處理平台推送的消息</span>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="f1d59f9e-0806-4108-86df-24ed51164e33"><ac:plain-text-body><![CDATA[ [SensorsFocusHelper dealSensorsFocusAction:userInfo link:^(NSString * _Nonnull urlString) {
    ]]></ac:plain-text-body></ac:structured-macro>
    <span style="color: #008200">// TODO 處理打開 URL 消息,--> 請處理 URL</span>
    } customize:^(NSDictionary * _Nonnull customizedDic) {
    <span style="color: #008200">// TODO 處理自定義消息,--> 請處理自定義消息</span>
    }];

    completionHandler(); <span style="color: #008200">// 系统要求執行这个方法</span>
    }


个推推送

上報推送 ID

為了保证登錄之後的用户也能设置 clientId 属性,需要在 GeTuiSdkDelegate 协议方法 GeTuiSdkDidRegisterClient:  和调用神策 - login: 接口之後,各上報一次 clientId。

  • (<span style="color: #336699"><strong>void</strong></span>)GeTuiSdkDidRegisterClient:(NSString *)clientId {
    <span style="color: #008200">// 將clientId 保存到用户表的 getui_id 字段中(这里的 getui_id 只是一个示例字段)</span>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="e4b36df8-38d8-461d-9b3b-62da7a8b5a55"><ac:plain-text-body><![CDATA[ [[SensorsAnalyticsSDK sharedInstance] set:@<span style="color: #003366">"getui_id"</span> to:clientId];
    ]]></ac:plain-text-body></ac:structured-macro>
    }

// 為了保证登錄後的用户也能正确设置 clientId,调用 login 之後,再次上報 clientId
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d45dc9d3-b805-4728-8788-9598045f146e"><ac:plain-text-body><![CDATA[[[SensorsAnalyticsSDK sharedInstance] login:<#登錄 ID#>];
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="14b3bac9-defe-43b6-891c-8775c0a65e37"><ac:plain-text-body><![CDATA[[[SensorsAnalyticsSDK sharedInstance] set:@"getui_id" to:GeTuiSdk.clientId];

]]></ac:plain-text-body></ac:structured-macro>


記錄 「推送打開」事件并處理智能运营平台推送的消息

// iOS10 一下版本,iOS 7 Support

  • (<span style="color: #336699"><strong>void</strong></span>)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler(悲伤)<span style="color: #336699"><strong>void</strong></span> (^)(UIBackgroundFetchResult))completionHandler {
    <span style="color: #008200"><ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="5a38fa73-0920-47af-8f45-0bcec5a3fb64"><ac:plain-text-body><![CDATA[// [ GTSdk ]:將收到的APNs信息传给个推统计

    \\

    [GeTuiSdk handleRemoteNotification:userInfo];
    ]]></ac:plain-text-body></ac:structured-macro>
    <span style="color: #008200">// 記錄 推送打開 事件</span>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="53d99eea-3bc4-468f-a014-fa784d5d5e80"><ac:plain-text-body><![CDATA[ [SensorsFocusHelper trackSensorsFocusAppOpenNotificationWithUserInfo:userInfo];
    ]]></ac:plain-text-body></ac:structured-macro>
    <span style="color: #008200">// 處理平台推送的消息</span>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="6acb64f2-e177-4da7-9dd4-35a728dd5298"><ac:plain-text-body><![CDATA[ [SensorsFocusHelper dealSensorsFocusAction:userInfo link:^(NSString * _Nonnull urlString) {
    ]]></ac:plain-text-body></ac:structured-macro>
    <span style="color: #008200">// TODO 處理打開 URL 消息,--> 請處理 URL</span>
    } customize:^(NSDictionary * _Nonnull customizedDic) {
    <span style="color: #008200">// TODO 處理自定義消息,--> 請處理自定義消息</span>
    }];
    completionHandler(UIBackgroundFetchResultNewData);
    }

    <span style="color: #008200">// iOS 10: 點擊通知進入App時觸發,在该方法内统计有效用户點擊數</span>

  • (<span style="color: #336699"><strong>void</strong></span>)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler<span style="color: #336699"><strong>void</strong></span> (^)())completionHandler {

    NSDictionary *userInfo = response.notification.request.content.userInfo;
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="9c47d91e-0887-4737-b459-1c98301d7de1"><ac:plain-text-body><![CDATA[ <span style="color: #336699"><strong>if</strong></span> ([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger <span style="color: #336699"><strong>class</strong></span>]]) {
    ]]></ac:plain-text-body></ac:structured-macro>
    <span style="color: #008200"><ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="efc60ecd-67f3-407a-abd7-bfaa9e7e3de7"><ac:plain-text-body><![CDATA[// [ GTSdk ]:將收到的APNs信息传给个推统计

    \\

    [GeTuiSdk handleRemoteNotification:userInfo];
    ]]></ac:plain-text-body></ac:structured-macro>
    }
    <span style="color: #008200">// 記錄 推送打開 事件</span>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="7607a3d8-852d-402e-b9a6-dcb01c495501"><ac:plain-text-body><![CDATA[ [SensorsFocusHelper trackSensorsFocusAppOpenNotificationWithUserInfo:userInfo];
    ]]></ac:plain-text-body></ac:structured-macro>
    <span style="color: #008200">// 處理平台推送的消息</span>
    <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="cf776877-47e0-4509-90bd-19f94d21e232"><ac:plain-text-body><![CDATA[ [SensorsFocusHelper dealSensorsFocusAction:userInfo link:^(NSString * _Nonnull urlString) {
    ]]></ac:plain-text-body></ac:structured-macro>
    <span style="color: #008200">// TODO 處理打開 URL 消息,--> 請處理 URL</span>
    } customize:^(NSDictionary * _Nonnull customizedDic) {
    <span style="color: #008200">// TODO 處理自定義消息,--> 請處理自定義消息</span>
    }];
    completionHandler(); <span style="color: #008200">// 系统要求執行这个方法</span>
    }


測試推送

  1. 首先發送推送 ID 到神策後,选择上報推送 ID 的 key(这里以 jiguang_id 為例),點擊測試推送。
  2. 填入測試机的推送 ID、推送标题、内容,如下图所示。
  3. 确认推送,可查看手机是否收到推送,以及查看埋點上報字段是否正确。

附錄

+ trackSensorsFocusAppOpenNotificationWithUserInfo: 方法詳情

/**
* 埋點"App 打開推送"事件。
*
* @param userInfo 包含與遠程通知相關的信息的字典
*/
+ (void)trackSensorsFocusAppOpenNotificationWithUserInfo:(NSDictionary *)userInfo {
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="43f88e75-27ef-4536-b6d3-6f50d31254e5"><ac:plain-text-body><![CDATA[ NSMutableDictionary *pushProperties = [NSMutableDictionary dictionary]; // track 字典
]]></ac:plain-text-body></ac:structured-macro>
@try { // sf_data
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="947dac39-cc6a-46ce-9e54-012c62361b98"><ac:plain-text-body><![CDATA[ NSData *jsonData = [userInfo[@"sf_data"] dataUsingEncoding:NSUTF8StringEncoding];
]]></ac:plain-text-body></ac:structured-macro>
NSError *error;
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="6dfc4694-2e01-4fc6-9158-cfa676ab960f"><ac:plain-text-body><![CDATA[ NSDictionary *sfDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="29657aad-49a3-4d7b-a222-84a73d032dd0"><ac:plain-text-body><![CDATA[ if (!error && [sfDictionary isKindOfClass:NSDictionary.class]) {
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="7d939581-a2c3-46d6-b622-a428a7626d28"><ac:plain-text-body><![CDATA[ pushProperties[@"$sf_msg_id"] = sfDictionary[@"sf_msg_id"]; // SF 消息 id
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="5390fd24-19bb-4b4e-be76-3f33c8e138c8"><ac:plain-text-body><![CDATA[ pushProperties[@"$sf_plan_id"] = sfDictionary[@"sf_plan_id"];
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="34c9be6a-4db7-4f2c-8855-7d60af5d0806"><ac:plain-text-body><![CDATA[ pushProperties[@"$sf_audience_id"] = sfDictionary[@"sf_audience_id"];
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="fd1cd830-7583-4654-b2d5-a1152bdcfb86"><ac:plain-text-body><![CDATA[ pushProperties[@"$sf_plan_strategy_id"] = sfDictionary[@"sf_plan_strategy_id"];
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="bb6a16c2-486e-4aba-8e61-d25394b9b32a"><ac:plain-text-body><![CDATA[ pushProperties[@"$sf_plan_type"] = sfDictionary[@"sf_plan_type"];
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="f36ab4ca-1ab6-421f-b7b8-51127031c90b"><ac:plain-text-body><![CDATA[ pushProperties[@"$sf_strategy_unit_id"] = sfDictionary[@"sf_strategy_unit_id"];
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="f37d3b7a-a11e-43ef-a69a-bf130044f36b"><ac:plain-text-body><![CDATA[ pushProperties[@"$sf_enter_plan_time"] = sfDictionary[@"sf_enter_plan_time"];
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="64a7c552-d698-42c1-9fb5-08295881fe5f"><ac:plain-text-body><![CDATA[ pushProperties[@"$sf_channel_id"] = sfDictionary[@"$sf_channel_id"];
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="a73b0639-9f55-4026-9c87-29517a6bec14"><ac:plain-text-body><![CDATA[ pushProperties[@"$sf_channel_category"] = sfDictionary[@"sf_channel_category"];
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="340bb5f4-8538-4eef-871e-047d19c35144"><ac:plain-text-body><![CDATA[ pushProperties[@"$sf_channel_service_name"] = sfDictionary[@"sf_channel_service_name"];
]]></ac:plain-text-body></ac:structured-macro>
 
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="9aec5b0f-c739-44ba-8396-18bc63b86221"><ac:plain-text-body><![CDATA[ if ([sfDictionary[@"sf_landing_type"] isEqualToString:@"LINK"]) { // 打開 URL
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="7440db39-f204-4840-95aa-1dee4996d729"><ac:plain-text-body><![CDATA[ pushProperties[@"$sf_link_url"] = sfDictionary[@"sf_link_url"];
]]></ac:plain-text-body></ac:structured-macro>
}
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="1e9bc41f-c3e7-47cf-ad53-0a2394450c4c"><ac:plain-text-body><![CDATA[ NSDictionary *customizedParams = sfDictionary[@"customized"];
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="570f7334-669f-44c4-aaa6-572b458355c9"><ac:plain-text-body><![CDATA[ if ([customizedParams isKindOfClass:NSDictionary.class]) {
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="13eba176-92dd-402b-9770-64e35ffc4468"><ac:plain-text-body><![CDATA[ [pushProperties addEntriesFromDictionary:customizedParams];
]]></ac:plain-text-body></ac:structured-macro>
}
}
} @catch (NSException *exception) {
}
@try { // aps alert
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="48e6c092-514d-45cd-94c6-b10aeefab226"><ac:plain-text-body><![CDATA[ NSDictionary *apsAlert = userInfo[@"aps"][@"alert"];
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2a526c3f-68a2-40a3-b1f4-36a78ea87c2c"><ac:plain-text-body><![CDATA[ if ([apsAlert isKindOfClass:NSDictionary.class]) {
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="17753cf3-ba6b-4d46-a5b5-d5a373cd4464"><ac:plain-text-body><![CDATA[ pushProperties[@"$sf_msg_title"] = apsAlert[@"title"]; // 推送标题
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="4af9be80-f041-4845-9671-af29db837322"><ac:plain-text-body><![CDATA[ pushProperties[@"$sf_msg_content"] = apsAlert[@"body"]; // 推送内容
]]></ac:plain-text-body></ac:structured-macro>
}
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="6ddfc6d8-822c-44d5-ad32-3b9bc1f73119"><ac:plain-text-body><![CDATA[ else if ([apsAlert isKindOfClass:NSString.class]) {
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="762db6ca-5a2e-46dd-a011-96f341a9ee72"><ac:plain-text-body><![CDATA[ pushProperties[@"$sf_msg_content"] = apsAlert; // 推送内容
]]></ac:plain-text-body></ac:structured-macro>
}
} @catch (NSException *exception) {
}
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="11d48113-2275-4972-a70c-d9145b5744c3"><ac:plain-text-body><![CDATA[ [SensorsAnalyticsSDK.sharedInstance track:@"$AppPushClick" withProperties:pushProperties];
]]></ac:plain-text-body></ac:structured-macro>
}


+ dealSensorsFocusAction: link:customize: 方法詳情

/// 神策智能运营處理推送消息,做页面跳轉
/// @param userInfo 包含與遠程通知相關的信息的字典
/// @param aLink 打開 URL 的回调
/// @param aCustomized 處理自定義消息回调
+ (BOOL)dealSensorsFocusAction:(NSDictionary *)userInfo link(悲伤)void ()(NSString * _Nonnull))aLink customize(悲伤)void ()(NSDictionary * _Nonnull))aCustomized {
@try {
// 解析 sf_data
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ce537c7b-5435-4b14-8fe0-03aca8048e13"><ac:plain-text-body><![CDATA[ NSString *jsonString = userInfo[@"sf_data"];
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="9cdf75c5-517a-4562-86a7-e0b3d5e9618f"><ac:plain-text-body><![CDATA[ NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
]]></ac:plain-text-body></ac:structured-macro>
NSError *error;
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="7380bc4d-f056-42e5-9e3c-f8acedfc691e"><ac:plain-text-body><![CDATA[ NSDictionary *sfDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
]]></ac:plain-text-body></ac:structured-macro>
if (!sfDictionary

error) {
return NO;
}
 
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="065984c3-a394-47ed-9f91-8b19c0d58584"><ac:plain-text-body><![CDATA[ NSString *sf_landing_type = sfDictionary[@"sf_landing_type"];
]]></ac:plain-text-body></ac:structured-macro>
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="9e034b33-d3c7-4fbb-b86f-d17af27c0fc8"><ac:plain-text-body><![CDATA[ if ([sf_landing_type isEqualToString:@"LINK"]) {
]]></ac:plain-text-body></ac:structured-macro>
// 打開 URL
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="1ce28757-794d-4cea-a3a2-46acd236134b"><ac:plain-text-body><![CDATA[ NSString *url = sfDictionary[@"sf_link_url"];
]]></ac:plain-text-body></ac:structured-macro>
if (aLink) {
aLink(url);
}
 
}
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2b47bd16-511a-4808-afa0-809e86ff0a35"><ac:plain-text-body><![CDATA[ else if ([sf_landing_type isEqualToString:@"CUSTOMIZED"]) {
]]></ac:plain-text-body></ac:structured-macro>
// 處理自定義消息
// 如果你们已经有了根据附加字段跳轉邏輯,此處无需處理。(因為神策智能运营發的推送消息会兼容极光控制台的 "附加字段")
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="40c294b8-e83e-4b9e-8d2e-a3b449dcbb4d"><ac:plain-text-body><![CDATA[ NSDictionary *customized = sfDictionary[@"customized"];
]]></ac:plain-text-body></ac:structured-macro>
if (aCustomized) {
aCustomized(customized);
}
}
return YES;
} @catch (NSException *exception) {
}
return NO;
}



附錄方法的封装類

如果不想把附錄中的示例方法一个个複製到项目中,可以使用封装好的工具類 SensorsFocusHelper 来调用示例方法。使用步骤如下:

  1. 下载 SensorsFocusHelper 類,解壓力後複製到项目中
  2. 引入 SensorsFocusHelper.h 
  3. 调用 SensorsFocusHelper 類中的同名方法

附錄中 + dealSensorsFocusAction: link:customize: 方法需要開發者在 TODO 注释的位置添加上具體的業務跳轉邏輯,SensorsFocusHelper 類將具體的業務跳轉邏輯封装成 block 回调,具體的使用方式請参考以下示例:

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="1d7ec18a-b245-4f38-8544-1a655b8ca70a"><ac:plain-text-body><![CDATA[

[SensorsFocusHelper dealSensorsFocusAction:userInfo link:^(NSString * _Nonnull urlString) {
]]></ac:plain-text-body></ac:structured-macro>
// TODO 處理打開 URL 消息,--> 請處理 URL
} customize:^(NSDictionary * _Nonnull customizedDic) {
// TODO 處理自定義消息,--> 請處理自定義消息
}];