HomeiOS Developmentswift - Can not obtain push notification on iOS Simulator

swift – Can not obtain push notification on iOS Simulator


I am testing silent push notifications in my app, however after I drag a .apns file into the simulator, it does not set off the didReceiveRemoteNotification callback technique.

I’ve created a minimal reproducible mission:

Fundamental App File

import SwiftUI
import UIKit

@most important
struct PushPlayApp: App {
  @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
  
    var physique: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

class AppDelegate: NSObject, UIApplicationDelegate {
    func utility(
        _ utility: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
    ) -> Bool {
        utility.registerForRemoteNotifications()
        return true
    }
    
  func utility(_ utility: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Knowledge) {
    print("Success")
    let decodedToken = deviceToken.map { information in String(format: "%02.2hhx", information) }.joined()
    print("Token:", decodedToken)
  }
  
  func utility(_ utility: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: any Error) {
    print("Fail", String(describing: error))
  }
  
  func utility(_ utility: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    print("Did Obtain Distant Notification", String(describing: userInfo))
    completionHandler(.newData)
  }
}

.apns-file

{
  "aps": {
    "content-available": 1
  },
  "some-data": "hey",
  "Simulator Goal Bundle": "my.bundle.id"
}

Configuration

  • I’ve added the “Push Notification” functionality to my mission, and verified that the robotically managed provisioning profiles embody that Functionality
  • I’ve added the “Background Modes” functionality and ticket off “Distant notifications”. Equally, this seem within the provisioning profiles.
  • I’ve verified that I’ve this entitlements key:

    aps-environment
    growth

What’s occurring

After I launch the app, I get the callback with a deviceToken, however after I drag within the .apns file nothing occurs. I make sure that to have the app I working within the background whereas testing. I’ve additionally tried triggering a notification from the Push notification console on-line, however with no luck.

What’s lacking?!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments