集成 Push

更新时间:2022-03-03 08:08:56下载pdf

基于 Tuya SDK 开发的 App,Tuya 平台支持 Push 功能,支持给用户发送运营 Push 和产品的告警 Push

Xcode 配置

点击 Xcode 项目 - TARGETS - Capabilities, 将 Push Notification 的开关打开,效果如下图所示:

集成 Push

涂鸦开发者平台配置

登录涂鸦 IoT 工作台 - App SDK - 配置 - 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 {
                //点击不允许
            }
        }];
    }

}

注册 PushId

didRegisterForRemoteNotificationsWithDeviceToken 中注册 pushId 到 Tuya SDK


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

接收通知

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

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


}

发送 Push

新增运营 Push

涂鸦IoT平台 - 运营 - App消息 - 新增消息
集成 Push

设备消息 Push

涂鸦IoT平台 - 产品 - 消息推送 - 设备信息推送

更多详细操作,请参考推送设备信息.

集成 Push