I've created a minimal reproducible project:
Main App File
Код: Выделить всё
import SwiftUI
import UIKit
@main
struct PushPlayApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
class AppDelegate: NSObject, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
application.registerForRemoteNotifications()
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("Success")
let decodedToken = deviceToken.map { data in String(format: "%02.2hhx", data) }.joined()
print("Token:", decodedToken)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: any Error) {
print("Fail", String(describing: error))
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print("Did Receive Remote Notification", String(describing: userInfo))
completionHandler(.newData)
}
}
< /code>
.apnsКод: Выделить всё
{
"aps": {
"content-available": 1
},
"some-data": "hello",
"Simulator Target Bundle": "my.bundle.id"
}
< /code>
Configuration
[list]
[*]I've added the "Push Notification" capability to my project, and verified that the automatically managed provisioning profiles include that Capability
[*]I've added the "Background Modes" capability and ticket off "Remote notifications". Similarly, this appear in the provisioning profiles.
[*]I have verified that I have this entitlements key:
[/list]
aps-environment
development
< /code>
What's happening
When I launch the app, I get the callback with a deviceToken, but when I drag in the .apnsПодробнее здесь: https://stackoverflow.com/questions/797 ... -simulator
Мобильная версия