Self-Managed Integration
Last updated
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
PushSDK.disableMethodSwizzling()
PushSDK.setConfiguration(appKey: "REPLACE_WITH_SDK_KEY", withLaunchOptions: launchOptions)
PushSDK.showNativeNotificationPermissionPrompt() { granted, settings, error in
// optional callback
print("User accepted permissions: \(granted)")
}
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
PushSDK.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
PushSDK.application(application, didFailToRegisterForRemoteNotificationsWithError: error)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
PushSDK.application(application, didReceiveRemoteNotification: userInfo) { result in
// Capture the PushSDK UIBackgroundFetchResult, modify as needed for your own logic
completionHandler(result)
}
}
// For integrations targeting iOS version 10 or earlier
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
PushSDK.application(application, didReceiveRemoteNotification: userInfo)
}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[PushSDK disableMethodSwizzling];
[PushSDK setConfigurationAppKey:@"REPLACE_WITH_SDK_KEY" withLaunchOptions:launchOptions];
[PushSDK showNativeNotificationPermissionPrompt:^(BOOL granted, UNNotificationSettings * _Nonnull settings, NSError * _Nullable error) {
NSLog(@"User accepted permissions: %@", granted ? @"YES" : @"NO");
}];
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[PushSDK application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
[PushSDK application:application didFailToRegisterForRemoteNotificationsWithError: error];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
[PushSDK application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:^(UIBackgroundFetchResult result) {
// Capture the PushSDK UIBackgroundFetchResult, modify as needed for your own logic
completionHandler(result);
}];
}
// For integrations targeting iOS version 10 or earlier
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[PushSDK application:application didReceiveRemoteNotification:userInfo];
}public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
PushSDK.userNotificationCenter(center, willPresent: notification) { options in
// Capture the PushSDK UNNotificationPresentationOptions, modify as needed for your own logic
completionHandler(options)
}
}
public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
PushSDK.userNotificationCenter(center, didReceive: response) {
completionHandler()
}
}- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
[PushSDK userNotificationCenter:center willPresent:notification withCompletionHandler:^(UNNotificationPresentationOptions options) {
// Capture the PushSDK UNNotificationPresentationOptions, modify as needed for your own logic
completionHandler(options);
}];
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
{
[PushSDK userNotificationCenter:center didReceive:response withCompletionHandler:^{
completionHandler();
}];
}