Configuring Notifications
After the initial initialization is complete, you need to add the following SDK calls to enable push notifications:
- Swift
- Objective-C
// MARK: - Remote Notifications
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Threads.threads().applicationDidRegisterForRemoteNotifications(withDeviceToken: deviceToken)
}
// MARK: - UNUserNotificationCenterDelegate
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// Check for application launched from notification
if response.actionIdentifier == UNNotificationDefaultActionIdentifier {
let userInfo = response.notification.request.content.userInfo
if Threads.threads().isThreadsOriginPushUserInfo(userInfo) {
// Application launched from Threads notification
} else {
// Application launched from other notifications
}
}
completionHandler()
}
#pragma mark - Remote Notifications
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[[Threads threads] applicationDidRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[[Threads threads] applicationDidFailToRegisterForRemoteNotificationsWithError:error];
}
#pragma mark - UNUserNotificationCenterDelegate
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler API_AVAILABLE(ios(10.0)){
// Check for application launched from notification
if ([response.actionIdentifier isEqualToString: UNNotificationDefaultActionIdentifier]) {
NSDictionary *userInfo = response.notification.request.content.userInfo;
if ([[Threads threads] isThreadsOriginPushUserInfo:userInfo]) {
// Application launched from Threads notification
} else {
// Application launched from other notifications
}
}
completionHandler();
}
Integration with Push Lite
note
This section is only relevant for projects that already use the push-lite SDK to deliver notifications.
To configure and integrate push-lite, follow the instructions provided with the SDK.
Initialization of the Chat Center library must go first:
- Swift
- Objective-C
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Step 1: Configure Threads Framework
let threads = Threads.threads()
threads.registrationAtStartupDisable = SettingsBundleHelper.getRegistrationAtStartupDisable()
threads.isClientIdEncrypted = Configuration.clientIdEncrypted()
threads.isShowsNetworkActivity = true
guard let providerUid = Configuration.providerUid() else { fatalError("Set providerUid for threadsGate transportProtocol.") }
threads.configureTransportProtocol(
with: self,
webSocketURL: URL(string: Configuration.webSocketURL())!,
providerUid: providerUid,
restURL: URL(string: Configuration.restServerURL())!,
dataStoreURL: URL(string: Configuration.dataStoreURL())!
)
// Step 2: Configure PushLite Framework
pushLite = EDNAPushLite(delegate: self)
pushLite.appGroup = "group.io.edna.chatcenter.demo"
pushLite.autoRegisterForNotification = false
pushLite.logEnable = true
pushLite.start()
// Step 3: Register device for remote notifications
...
return true
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Step 1: Configure Threads Framework
Threads *threads = [Threads threads];
threads.isDebugLoggingEnabled = YES;
[threads configureTransportProtocolWithDelegate:self
providerUid:@"PROVIDER_UID"
webSocketURL: [NSURL URLWithString:@"Ссылка на WebSocket API"]
restURL: [NSURL URLWithString:@"Ссылка на REST API"]
dataStoreURL: [NSURL URLWithString:@"Ссылка на DataStore API"]];
// Step 2: Configure PushLite Framework
pushLite = [[EDNAPushLite alloc] initWithDelegate: self];
pushLite.appGroup = @"group.io.edna.chatcenter.demo";
pushLite.autoRegisterForNotification = NO;
pushLite.logEnable = YES;
[pushLite start];
// Step 3: Register device for remote notifications
...
return YES;
}
The values from the notification delegates are passed in the same order:
- Swift
- Objective-C
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Threads.threads().applicationDidRegisterForRemoteNotifications(withDeviceToken: deviceToken)
pushLite.appDelegate.didRegisterForRemoteNotifications(withDeviceToken: deviceToken)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
pushLite.appDelegate.didFailToRegisterForRemoteNotifications(withError: error)
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[[Threads threads] applicationDidRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
[[pushLite appDelegate] didRegisterForRemoteNotificationsWithDeviceToken: deviceToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[[pushLite appDelegate] didFailToRegisterForRemoteNotificationsWithError: error];
}