Smart App SDKSmart Life App SDKiOS PlatformIntegrate with Push Notifications

Integrate with Push Notifications

Last Updated on : 2023-09-19 03:01:03download

The apps developed based on Smart Life App SDK support push notifications. You can integrate with this feature to send push notifications respecting promotional operations and product alerts to app users.

Configure a project

  1. Create a project in Xcode.

  2. Choose TARGETS > Capabilities and set Push Notifications to ON.

    Integrate with Push Notifications

  3. Log in to the Tuya IoT Development Platform and go to the SDK Development page. On the Certificates tab, you can configure and upload a push certificate.

    Integrate with Push Notifications

Initialize Push

Call the API method didFinishLaunchingWithOptions to initialize 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) {
        // Adds the following code block for iOS 10.
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        center.delegate = self;
        UNAuthorizationOptions types10 = UNAuthorizationOptionBadge|UNAuthorizationOptionAlert|UNAuthorizationOptionSound;
        [center requestAuthorizationWithOptions:types10 completionHandler:^(BOOL granted, NSError * _Nullable error) {
            if (granted) {
                // Allows this authorization.
            } else {
                // Rejects this authorization.
            }
        }];
    }

}

Register a push notification ID

Registers pushId to Smart Life App SDK in didRegisterForRemoteNotificationsWithDeviceToken.

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

Receive push notifications

Receives remote push notifications by calling the delegate method didReceiveRemoteNotification.

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

}

Send push notifications

After you integrate with the capabilities of push notifications, you can configure push notifications on the Tuya IoT Development Platform.

Create an operation push notification

To create a marketing push notification, log in to the Tuya IoT Development Platform and go to the Marketing push page. Then, users can receive your in-app message regarding new arrivals, trending information, and more. This can help to build user engagement.

Integrate with Push Notifications

Create a device push notification

To create a device push notification, log in to the Tuya IoT Development Platform, and in the left-side navigation pane, choose Product > Notifications. For more information, see Configure Push Notification.

Integrate with Push Notifications