私のアプリがバックグラウンドまたはフォアグラウンドにあるときに私は通知を受け取ることができますが、私のアプリはkillです。私は通知を得ることができません。 私はfcmを使用しています... これは郵便配達員経由で呼び出す私のペイロードです。私のアプリがkillであるときに通知を受け取らない
{
"registration_ids":
["...."],
"notification":{
"sound":"default",
"title":"testNotif",
"body":"welcome in the shop Apple owner"
}
}
これは私のappdelegateです:
import UIKit
import UserNotifications
import Firebase
import FirebaseInstanceID
import FirebaseMessaging
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 10.0, *) {
let authOptions : UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_,_ in })
UNUserNotificationCenter.current().delegate = self
FIRMessaging.messaging().remoteMessageDelegate = self
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
FIRApp.configure()
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
}
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
FIRInstanceID.instanceID().setAPNSToken(deviceToken as Data, type: FIRInstanceIDAPNSTokenType.prod)
}
func tokenRefreshNotification(notification: NSNotification) {
if let refreshedToken = FIRInstanceID.instanceID().token() {
print("InstanceID token: \(refreshedToken)")
}
connectToFcm()
}
func connectToFcm() {
FIRMessaging.messaging().connect { (error) in
if (error != nil) {
print("Unable to connect with FCM. \(error)")
} else {
print("Connected to FCM.")
}
if let refreshedToken = FIRInstanceID.instanceID().token() {
Common.tokenFCM = refreshedToken
print("InstanceID token: \(refreshedToken)")
}
}
}
func applicationDidBecomeActive(_ application: UIApplication) {
connectToFcm()
}
}
@available(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {
private func userNotificationCenter(center: UNUserNotificationCenter,
willPresentNotification notification: UNNotification,
withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
print("<<<<<<< %@", userInfo)
}
}
extension AppDelegate : FIRMessagingDelegate {
func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) {
print(">>>>> %@", remoteMessage.appData)
}
}
を確認することができますplzはこのリンクhttp://stackoverflow.com/questions/36929869/push-notification-not-receiving-in-background-iosを読みます/ 36934771#36934771 –