Documentation
Website
  • Getting Started
  • Customer Journey
    • Creating a Customer Journey
    • Understanding the Journey
    • Performance Dashboard
    • Pre-built Templates
  • Cross-Channel Messages
    • Mobile Push
    • Web Push
    • In-App Message
    • SMS/LMS
    • Webhook
  • Data Integration
    • User ID
    • Events
    • Tags
    • Integrating Amplitude
    • Integrating Mixpanel
  • Audience
    • Segments
    • Device Management
  • Engagement Tools
    • Message Personalization
    • Template
  • Analytics & Insights
    • Dashboard
    • Real-time Analytics
  • Guide for Developers
    • Mobile SDK Setup
      • Android SDK Setup
      • iOS SDK Setup
      • React Native SDK Setup
      • Flutter SDK Setup
      • Additional Setup
        • Android: FCM Setup (v1)
        • Android: Notification Icons
        • iOS: APNS Setup
        • iOS: Disable Swizzling
    • Web SDK Setup
    • REST API Reference
    • Mobile SDK Reference
    • Web SDK Reference
Powered by GitBook
On this page
  • 1. Required Steps
  • 2. Add a property to Info.plist
  • 4. Update AppDelegate
  • 5. Update UNUserNotificationCenter
  • 6. Update UNNotificationServiceExtension
  1. Guide for Developers
  2. Mobile SDK Setup
  3. Additional Setup

iOS: Disable Swizzling

PreviousiOS: APNS SetupNextWeb SDK Setup

Last updated 1 year ago

FlareRain iOS SDK uses Method Swizzling to replace the required method implementation for push notification operation at runtime with its own. As a result, it is possible to achieve a more streamlined integration by eliminating the need for a complicated implementation process.

However, if you want to use it with other push services, you need to disable swizzling so that all services can share the original method. Disabling swizzling requires adding some code.

But don't worry! We have created all 1:1 correspondence methods so that you can integrate very easily. Follow this guide step by step to disable Method Swizzling.

1. Required Steps

Familiarize yourself with the tasks required to disable Method Swizzling. Just add 5 lines!

  1. Update SDK version 1.1.0 or higher

  2. Add FlareLaneSwizzlingEnabled: false to Info.plist

  3. Add 1 method to AppDelegate

  4. Add 2 methods to UNUserNotificationCenter

  5. Add 2 methods to UNNotificationServiceExtension

2. Add a property to Info.plist

After selecting the target project in Xcode, go to Info -> Custom iOS Target Properties -> Add Row

Key: FlareLaneSwizzlingEnabled

Value: 'NO' with Boolean Type

4. Update AppDelegate

  1. application(:didRegisterForRemoteNotificationsWithDeviceToken:)

import FlareLane

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
  // ...
  func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    // Add the code below
    FlareLaneAppDelegate.shared.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
  }
  // ...
}
@implementation AppDelegate
// ...
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  // Add the code below
  [[FlareLaneAppDelegate shared] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
// ...
@end

5. Update UNUserNotificationCenter

  1. Set a delegate of UNUserNotificationCenterDelegate to your AppDelegate

  2. userNotificationCenter(:willPresent:withCompletionHandler:)

  3. userNotificationCenter(:didReceive:withCompletionHandler:)

import FlareLane

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // 1
    UNUserNotificationCenter.current().delegate = self
  }
}

extension AppDelegate: UNUserNotificationCenterDelegate {
  // 2
  func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    FlareLaneNotificationCenter.shared.userNotificationCenter(center, willPresent: notification, withCompletionHandler: completionHandler)
  }
  // 3
  func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    FlareLaneNotificationCenter.shared.userNotificationCenter(center, didReceive: response, withCompletionHandler: completionHandler)
  }
}
// AppDelegate.h
#import <UserNotifications/UserNotifications.h>

@interface AppDelegate : UIResponder <..., UNUserNotificationCenterDelegate>
@end

// AppDelegate.m
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // 1
  [[UNUserNotificationCenter currentNotificationCenter] setDelegate: self];
}

// 2
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
  [[FlareLaneNotificationCenter shared] userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
}
// 3
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler
{
  [[FlareLaneNotificationCenter shared] userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
@end

6. Update UNNotificationServiceExtension

  1. didReceive(:withContentHandler:)

  2. serviceExtensionTimeWillExpire()

import FlareLane

class NotificationService: UNNotificationServiceExtension {
  override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
    // 1
    // Only handle notifications sent by FlareLane.
    if FlareLaneNotificationServiceExtensionHelper.shared.isFlareLaneNotification(request) {
      FlareLaneNotificationServiceExtensionHelper.shared.didReceive(request, withContentHandler: contentHandler)
    } else {
      // ...
    }
  }
  
  override func serviceExtensionTimeWillExpire() {
    // 2
    FlareLaneNotificationServiceExtensionHelper.shared.serviceExtensionTimeWillExpire()
  }
}
@import FlareLane;

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
  // 1
  // Only handle notifications sent by FlareLane.
  if ([[FlareLaneNotificationServiceExtensionHelper shared] isFlareLaneNotification:request]) {
    [[FlareLaneNotificationServiceExtensionHelper shared] didReceive:request withContentHandler:contentHandler];
  } else {
    // ...  
  }  
}

- (void)serviceExtensionTimeWillExpire {
  [[FlareLaneNotificationServiceExtensionHelper shared] serviceExtensionTimeWillExpire];
  // ...
}