1. Integrate Push

For Apps developed based on Tuya SDK, the Tuya platform supports push function, including operation push to users and alarm push of products.

1.1. Configure Xcode

Clock project -> TARGETS -> Capabilities, and switch on the Push Notification . The effect is as follows.

ios-push

1.2. Configure the Tuya Developer Platform

Log in to the Tuya Developer Platform -> Enter App Service -> Configure the Push function -> Upload the push certificate.

ios-push-setting

1.3. Initialization

Initiate push in the didFinishLaunchingWithOptions method.


- (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 need the following code
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        center.delegate = self;
        UNAuthorizationOptions types10 = UNAuthorizationOptionBadge|UNAuthorizationOptionAlert|UNAuthorizationOptionSound;
        [center requestAuthorizationWithOptions:types10 completionHandler:^(BOOL granted, NSError * _Nullable error) {
            if (granted) {

            } else {

            }
        }];
    }

}

1.4. Register PushId

Register pushId in Tuya SDK in the didRegisterForRemoteNotificationsWithDeviceToken.


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

1.5. Receive Notification

Execute in the delegate method didReceiveRemoteNotification when the remote notification is received.

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


}

1.6. Send Push

1.6.1. Add Operation Push

Tuya Developer Platform -> User operation -> Message center -> Add message ios-push-setting

1.6.2. Add Alarm Push

Tuya Developer Platform -> Product -> Extended function -> Set alarm -> Add rules for alarms (apply the push mode) ios-push-setting

results matching ""

    No results matching ""