Ios 通知未通过Firebase控制台发出
我已经尝试了上述问题的所有可能解决方案,但仍然没有通过Firebase控制台收到设备通知。请建议Ios 通知未通过Firebase控制台发出,ios,swift,firebase,push-notification,firebase-cloud-messaging,Ios,Swift,Firebase,Push Notification,Firebase Cloud Messaging,我已经尝试了上述问题的所有可能解决方案,但仍然没有通过Firebase控制台收到设备通知。请建议 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { FIRApp.configure() if let remoteNotification = launchOptions?[UIApplicatio
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
FIRApp.configure()
if let remoteNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary {
self.handleNotification(remoteNotification as! [NSObject : AnyObject])
}
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
// Add observer for InstanceID token refresh callback.
NSNotificationCenter
.defaultCenter()
.addObserver(self, selector: #selector(AppDelegate.tokenRefreshNotificaiton),
name: kFIRInstanceIDTokenRefreshNotification, object: nil)
return true }
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
FIRMessaging.messaging().appDidReceiveMessage(userInfo)
NSNotificationCenter.defaultCenter().postNotificationName("reloadTheTable", object: nil)
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Sandbox)
}
func tokenRefreshNotificaiton(notification: NSNotification) {
guard let refreshedToken = FIRInstanceID.instanceID().token()
else {
return
}
print("InstanceID token: \(refreshedToken)")
utill.tokenDefault.setValue(refreshedToken, forKey: "tokenId")
connectToFcm()
}
调试器中也显示了一些firebase警告:如果您是从Xcode 8或更高版本部署应用程序,请确保已从图中所示的“项目目标功能”部分启用推送通知功能。
我认为问题在于ios版本。ios 10需要未使用的通知中心。尝试下面的代码,并将该函数添加到应用程序didFinishLaunching中
func registerForRemoteNotification() {
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
if error == nil{
UIApplication.shared.registerForRemoteNotifications()
}
}
}
else {
UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))
UIApplication.shared.registerForRemoteNotifications()
}
}
这个问题为我解决了。
我没有上传APN的开发证书。
已启用推送通知。上面的登录屏幕截图显示无法获取APNS令牌。请检查您是否收到设备令牌并已上载正确的p12证书。不确定是否已执行此操作,但您需要转到firebase项目设置,选择云消息并上传APNs开发证书以接收firebase通知。您还需要一个真实的设备才能接收通知。无法在模拟器上执行通知测试。