Push Notifications, Episode 6: Silent Notification | Kodeco

Learn how to handle a silent notification, downloading data in the background so it's ready when your user opens your app.


This is a companion discussion topic for the original entry at https://www.kodeco.com/1258151-push-notifications/lessons/6

I’m working on standalone watch app. I’m using OneSingal to push silence notification, but it doesn’t work. However it work for the alert notification.
This is the setup process. Link

Hello @ehwah ! Thank you so much for adding your question in the forum.

I’ll tag some team members here so they could look into this for you. Cheers!

Hello @gdelarosa @robertomachorro cc:ing you here. :blush:

If possible, please provide more details about your setup. Xcode changes a lot. Preferably also upload your code to Github and share a link here. Your Google Drive isn’t working at my end.

1 Like

Xcode

  • version 15.2
  • Using storyboard version
  • My certificate is not expire
  • I have Push Notification adding for capability
  • remote notifications checked

My Watch

  • watch series 7.
  • os version 10.3
  • Background App Refresh: Enabled
  • Lower power mode: Disable

My code

  • calling registerForRemoteNotifications() to get token after the user allow notification permission [Work]
let wkExt = WKExtension.shared()
                wkExt.registerForRemoteNotifications()
  • getting token from didRegisterForRemoteNotifications(withDeviceToken deviceToken: Data) and store the token id in OneSignal [Work]
func didRegisterForRemoteNotifications(withDeviceToken deviceToken: Data) {
        let token = deviceToken.reduce("") { $0 + String(format: "%02x", $1)}
        print(token)
        addDevice(token)
    }
  • wait for silent notification from didReceiveRemoteNotification() [Not Work]
func didReceiveRemoteNotification(_ userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (WKBackgroundFetchResult) -> Void) {
        print("did recieve remote notification", Date().description(with: .current))
        completionHandler(.newData)
    }

Testing on Apple Push Notification Tester Push Notifications Console

  • Alert Notification [Work]
  • Background Notification [Work]

Testing on OneSignal

  • Alert Notification [Work]
  • Background Notification [Not Work]

@Audrey please see above, thanks!

hi ehwah! this video course is from 2019, based on the first edition of the book, which has been updated three times, most recently in 2022. Have a look at section 8.3: Push Notifications by Tutorials, Chapter 8: Handling Common Scenarios | Kodeco for the Xcode 14 version. If you still have problems, ask the author @gargoyle in the Chapter 8 forum.

1 Like