diff --git a/ios/App/App/AppDelegate.swift b/ios/App/App/AppDelegate.swift index 5cf254c..fe66f70 100644 --- a/ios/App/App/AppDelegate.swift +++ b/ios/App/App/AppDelegate.swift @@ -9,7 +9,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { - return true + // Remove this method to stop OneSignal Debugging + //OneSignal.Debug.setLogLevel(.LL_VERBOSE) + + return true } func applicationWillResignActive(_ application: UIApplication) { diff --git a/ios/App/OneSignalNotificationServiceExtension/NotificationService.swift b/ios/App/OneSignalNotificationServiceExtension/NotificationService.swift index 9d61183..444ed32 100644 --- a/ios/App/OneSignalNotificationServiceExtension/NotificationService.swift +++ b/ios/App/OneSignalNotificationServiceExtension/NotificationService.swift @@ -9,6 +9,9 @@ class NotificationService: UNNotificationServiceExtension { var bestAttemptContent: UNMutableNotificationContent? override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { + + print("Running NotificationServiceExtension") + self.receivedRequest = request self.contentHandler = contentHandler self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) diff --git a/ios/App/OneSignalNotificationServiceExtension/OneSignalNotificationServiceExtension.entitlements b/ios/App/OneSignalNotificationServiceExtension/OneSignalNotificationServiceExtension.entitlements index 989031d..5cf2ff0 100644 --- a/ios/App/OneSignalNotificationServiceExtension/OneSignalNotificationServiceExtension.entitlements +++ b/ios/App/OneSignalNotificationServiceExtension/OneSignalNotificationServiceExtension.entitlements @@ -2,6 +2,8 @@ + aps-environment + development com.apple.security.application-groups group.com.wrenchboard.users.onesignal diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 8eb80e4..6bb821f 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -13,27 +13,46 @@ export class AppComponent { // Call this function when your app starts OneSignalInit(): void { + + // https://documentation.onesignal.com/docs/mobile-sdk + alert('OneSignalInit'); + + // 0 = None, 1 = Fatal, 2 = Errors, 3 = Warnings, 4 = Info, 5 = Debug, 6 = Verbose // Uncomment to set OneSignal device logging to VERBOSE - // OneSignal.Debug.setLogLevel(6); + OneSignal.Debug.setLogLevel(6); + // 0 = None, 1 = Fatal, 2 = Errors, 3 = Warnings, 4 = Info, 5 = Debug, 6 = Verbose // Uncomment to set OneSignal visual logging to VERBOSE - // OneSignal.Debug.setAlertLevel(6); + //OneSignal.Debug.setAlertLevel(6); + OneSignal.Debug.setAlertLevel(4); // NOTE: Update the init value below with your OneSignal AppId. OneSignal.init("13755f98-ec69-45fd-a2f1-d2166afcaa51"); + + // Location permissions enable geotagging in the OneSignal dashboard to send notifications to users based on their location + OneSignal.Location.setShared(false); let myClickListener = async function(event) { let notificationData = JSON.stringify(event); - alert(notificationData); + alert("CLICKED: " + notificationData); console.log('notificationOpenedCallback: ' + JSON.stringify(notificationData)); }; OneSignal.Notifications.addEventListener("click", myClickListener); - - /* OneSignal.Notifications.setNotificationOpenedHandler(function(opened) { - let notificationData = JSON.stringify(opened); - console.log('notificationOpenedCallback: ' + notificationData); - }); //*/ + + // Set a handler to run before displaying a notification while the app is in focus. + let myForegroundWillDisplayListener = async function(event) { + let notificationData = JSON.stringify(event); + alert("RECEIVED: " + notificationData); + console.log('foregroundWillDisplayCallback : ' + JSON.stringify(notificationData)); + + /// Display Notification, preventDefault to not display + event.preventDefault(); + + // Use notification.display() to display the notification after some async work + //event.notification.display(); + }; + OneSignal.Notifications.addEventListener('foregroundWillDisplay', myForegroundWillDisplayListener); // Prompts the user for notification permissions. // * Since this shows a generic native prompt, we recommend instead using an In-App Message to prompt for notification permission (See step 7) to better communicate to your users what notifications they will get.