我知道这个问题在这里已经问过几次了,但是他们也没有帮助我。
主要问题是,当我从testflight下载应用程序时,我没有收到推送通知。如果我将应用程序直接从xCode下载到我的iPhone,则推送通知有效。 我有一种将FCM令牌存储在Firestore中的方法。使用这些令牌,不同的设备在添加新帖子后应立即收到通知:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Thread.sleep(forTimeInterval: 0.1)
UNUserNotificationCenter.current().removeAllDeliveredNotifications() // For removing all delivered notification
UNUserNotificationCenter.current().removeAllPendingNotificationRequests() // For removing all pending notifications which are not delivered yet but scheduled.
FirebaseApp.configure()
Messaging.messaging().delegate = self
allowSendUserNotification()
registerForPushNotifications()
return true
}
func registerForPushNotifications() {
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
UIApplication.shared.registerUserNotificationSettings(settings)
}
UIApplication.shared.registerForRemoteNotifications()
}
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
FirebaseHelper.sharedInstance.storeFCMTokenFromUserInFirestore(fcmToken: fcmToken )
}
我在“签名和功能”中添加了通知。 这是我的.entitlements文件:
我还两次续签了证书。我使用生产证书。