Hi,
I'm trying to intercept incoming push notifications so I can extract the payload inside with an iOS client, using swift.
The client receives the notification just fine - notification shows if app is not active and I see the event in the logs (attached at bottom)
The iOS guide doesn't really mention interacting with incoming push notification themselves, but I found this guide on your site (iOS Integration Best Practices for Swift and Objective-C), and followed all the steps. However none of the functions in the notification handler are triggered when a push is received (receivedForegroundNotification, receivedBackgroundNotification, launchedFromNotification).
Don't know if it helps, but I have been able to get actions contained in the push to be triggered (according to the iOS guide).
Your help would be greatly appreciated.
Dave
relevant code in AppDelegate.swift:
var customPushHandler = PushHandler()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]?) -> Bool {
...
let config = UAConfig.default()
UAirship.takeOff(config)
UAirship.push().userPushNotificationsEnabled = true
PFUser.current()?["UAirshipChannelId"] = UAirship.push().channelID
PFUser.current()?.saveInBackground()
UAirship.push().pushNotificationDelegate = customPushHandler
...
}
PushHandler.swift:
import AirshipKit
class PushHandler: NSObject, UAPushNotificationDelegate {
func receivedForegroundNotification(notification: [NSObject : AnyObject], fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)) {
print("Received a notification while the app was already in the foreground: \(notification)")
completionHandler(UIBackgroundFetchResult.noData)
}
func launchedFromNotification(notification: [NSObject : AnyObject], fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)) {
print("The application was launched or resumed from a notification: \(notification)");
for (key, value) in notification {
if key as! String == "aps" {
print("body Found: \(value)")
}
}
completionHandler(UIBackgroundFetchResult.noData)
}
func receivedBackgroundNotification(notification: [NSObject : AnyObject], actionIdentifier identifier: String, completionHandler: () -> Void) {
print("The application was started in the background from a user notification button");
completionHandler()
}
func receivedBackgroundNotification(notification: [NSObject : AnyObject], fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)) {
print("A CONTENT_AVAILABLE notification was received with the app in the background: \(notification)");
completionHandler(UIBackgroundFetchResult.noData)
}
}
UA trace logs when a push is received:
2016-11-22 08:51:53.817493 iseeya[4437:8695132] [D] +[UAAppIntegration userNotificationCenter:willPresentNotification:withCompletionHandler:] [Line 136] Notification center will present notification: <UNNotification: 0x17403ed00; date: 2016-11-22 06:51:51 +0000, request: <UNNotificationRequest: 0x1740326c0; identifier: EEA00682-6DB8-4357-B2A4-1669DED83CE7, content: <UNNotificationContent: 0x1742e3e80; title: (null), subtitle: (null), body: 123 godammit !!!!, categoryIdentifier: , launchImageName: , peopleIdentifiers: (
), threadIdentifier: , attachments: (
), badge: (null), sound: (null), hasDefaultAction: YES, shouldAddToNotificationsList: YES, shouldAlwaysAlertWhileAppIsForeground: NO, shouldLockDevice: NO, shouldPauseMedia: NO, isSnoozeable: NO, fromSnooze: NO, darwinNotificationName: (null), darwinSnoozedNotificationName: (null), trigger: <UNPushNotificationTrigger: 0x174017ca0; contentAvailable: NO, mutableContent: NO>>>
2016-11-22 08:51:53.818201 iseeya[4437:8695132] [I] +[UAAppIntegration handleIncomingNotification:foregroundPresentation:completionHandler:] [Line 228] Received notification: {
"_" = "bd1cac0f-7540-47a2-b66b-fa66196d32ce";
aps = {
alert = "123 godammit !!!!";
};
}
2016-11-22 08:51:53.818441 iseeya[4437:8695132] [D] +[UAActionRunner runActionWithName:value:situation:metadata:completionHandler:] [Line 84] No action found with name aps, skipping action.
2016-11-22 08:51:53.819083 iseeya[4437:8695132] [D] +[UAActionRunner runActionWithName:value:situation:metadata:completionHandler:] [Line 84] No action found with name _, skipping action.
2016-11-22 08:51:57.461822 iseeya[4437:8695132] [D] __41-[UAAnalytics uploadOperationWithEvents:]_block_invoke [Line 536] Analytics data sent successfully. Status: 200
Comments
4 comments