Не может получить push -уведомление на симуляторе iOSIOS

Программируем под IOS
Ответить
Anonymous
 Не может получить push -уведомление на симуляторе iOS

Сообщение Anonymous »

I'm testing silent push notifications in my app, but when I drag a .apns file into the simulator, it doesn't trigger the didReceiveRemoteNotification callback method.
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
-file

Код: Выделить всё

{
"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
Файл ничего не происходит. Я обязательно имею приложение, которое я работаю в фоновом режиме во время тестирования. Я также попытался запустить уведомление из консоли уведомлений Push, но без повезло.>

Подробнее здесь: https://stackoverflow.com/questions/797 ... -simulator
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»