Last Updated on : 2023-05-22 06:38:23
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.
Create a project in Xcode.
Choose TARGETS > Capabilities and set Push Notifications to ON.
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.
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.
}
}];
}
}
Registers pushId
to Smart Life App SDK in didRegisterForRemoteNotificationsWithDeviceToken
.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[TuyaSmartSDK sharedInstance].deviceToken = deviceToken;
}
Receives remote push notifications by calling the delegate method didReceiveRemoteNotification
.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void(^)(UIBackgroundFetchResult))completionHandler {
}
After you integrate with the capabilities of push notifications, you can configure push notifications on the Tuya IoT Development Platform.
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.
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.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback