Hi,
As the Chabok doc says, I have registered user at Chabok when the apple push notification permission dialog needed to be shown. here is the code (in first ViewController after showing some message about push notification):
let userId = User.currentUser?.id ?? generateRandomId()
(UIApplication.shared.delegate as? AppDelegate)?.manager?.registerUser(userId)
And here is my AppDelegate
didFinishLaunchingWithOptions
func:
self.manager = PushClientManager.default()
PushClientManager.setDevelopment(isDebug)
manager?.registerApplication(ChabokCredentialInfo.appID, apiKey: ChabokCredentialInfo.sdkKey, userName: ChabokCredentialInfo.username, password: ChabokCredentialInfo.password)
manager?.addDelegate(self)
manager?.enableLocationOnLaunch = true
And other AppDelegate
function as Chabok doc says:
func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
self.manager?.application(application, didReceive: notification)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
self.manager?.application(application, didReceiveRemoteNotification: userInfo)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
self.manager?.application(application, didFailToRegisterForRemoteNotificationsWithError: error)
}
func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {
self.manager?.application(application, didRegister: notificationSettings)
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("APNs token retrieved: \(deviceToken as NSData)")
self.manager?.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
So here is the problem, with this configs and registration flow, every push notification is being arrived from the APNs channel, not Chabok exclusive connection, event when the app is in foreground. and no functions of PushClientManagerDelegate
is being called for incoming push notifications. this issue cause the app to have no control over incoming push notifications.
As a workaround I put this code before registering user to Chabok:
if #available(iOS 10.0, *) {
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
UIApplication.shared.registerUserNotificationSettings(settings)
}
UIApplication.shared.registerForRemoteNotifications()
let userId = User.currentUser?.id ?? generateRandomId()
(UIApplication.shared.delegate as? AppDelegate)?.manager?.registerUser(userId)