iOS Push Message Integration
1
2




3
4
import Flutter
import Hackle
import UIKit
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
...
// Add inside existing implemented code
// Request push permission in iOS app
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: { _, _ in }
)
NUserNotificationCenter.current().delegate = self
application.registerForRemoteNotifications()
...
}
override func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
// Send APNs push token to Hackle server
Hackle.setPushToken(deviceToken)
}
}5
import Flutter
import Hackle
import UIKit
@main
@objc class AppDelegate: FlutterAppDelegate {
...
// Add inside existing implemented code
// Foreground push message
override func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions
) -> Void) {
if Hackle.userNotificationCenter(
center: center, willPresent: notification, withCompletionHandler: completionHandler
) {
// Succefully processed notification
// Automatically consumed completion handler
return
} else {
// Received not hackle notification or error
print("Do something")
if #available(iOS 14.0, *) {
completionHandler([.list, .banner])
} else {
completionHandler([.alert])
}
}
}
}6
import Flutter
import Hackle
import UIKit
@main
@objc class AppDelegate: FlutterAppDelegate {
...
// Add inside existing implemented code
// push click
override public func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
if let _ = Hackle.handleNotification(response: response) {
// process hackle notification
} else {
// not hackle notification or error
print("do something")
}
// handleNotification does not call completionHandler,
// so you must call completionHandler regardless of whether it is a Hackle push.
completionHandler()
}
}7
8
Hackle Environment
APNs Environment
Build Environment
Deep Link Navigation
Last updated