集成 Push

更新时间:2023-09-19 03:01:03下载pdf

基于涂鸦 智能生活 App SDK 开发的 App,支持消息推送(Push)功能,即给用户发送运营 Push 和产品的告警 Push。

项目配置

  1. 打开您的 XCode 项目。

  2. TARGETS > Capabilities 的路径,打开 Push Notifications 的开关。

    集成 Push

  3. 登录 涂鸦 IoT 平台,在您的 App SDK 配置页面,配置 Push 证书 和上传 Push 证书。

    集成 Push

初始化 Push

didFinishLaunchingWithOptions 方法中,初始化 Push:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [application registerForRemoteNotifications];
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) {
        //iOS10 需要加下面这段代码
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        center.delegate = self;
        UNAuthorizationOptions types10 = UNAuthorizationOptionBadge|UNAuthorizationOptionAlert|UNAuthorizationOptionSound;
        [center requestAuthorizationWithOptions:types10 completionHandler:^(BOOL granted, NSError * _Nullable error) {
            if (granted) {
                //点击允许
            } else {
                //点击不允许
            }
        }];
    }

}

注册 Push ID

didRegisterForRemoteNotificationsWithDeviceToken 中,注册 pushId 到智能生活 App SDK。

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    [ThingSmartSDK sharedInstance].deviceToken = deviceToken;
}

接收通知

接收到远程通知,在代理方法 didReceiveRemoteNotification 中执行。

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void(^)(UIBackgroundFetchResult))completionHandler {

}

发送 Push

集成 Push 能力后,您就可以在涂鸦 IoT 平台进行每次的 Push 推送设置。

新增运营 Push

涂鸦 IoT 平台营销推送 页面,新建App消息推送。用户会在 App 上接收到您的推送提醒,新品上市推荐或者生活温馨提醒等信息,方便有效营销您的用户。

集成 Push

新增设备消息

涂鸦 IoT 平台消息推送 页面,完成设备信息推送。更多详细操作,请参考 推送设备信息

集成 Push