ios – FCM Swift 3 – 没有出现通知

ios – FCM Swift 3 – 没有出现通知,第1张

概述我知道你之前偶然发现了这个问题;事实上好几次.但我已经按照提供给我的每个建议 here, here甚至 here. (用Swift 3编写,在Xcode 8.1上运行) 是的,我的功能通知已经开启.甚至我的后台模式远程功能开启 – 我尝试打开和关闭FirebaseAppDelegateProxy,检查证书(为什么,是的,它指向正确的应用程序包),移动了 application.registerFo 我知道你之前偶然发现了这个问题;事实上好几次.但我已经按照提供给我的每个建议 here,here甚至 here.

(用Swift 3编写,在Xcode 8.1上运行)

是的,我的功能通知已经开启.甚至我的后台模式远程功能开启 – 我尝试打开和关闭FirebaseAppDelegateProxy,检查证书(为什么,是的,它指向正确的应用程序包),移动了

application.registerForRemoteNotifications()

哭了,消耗了大量的糖,向上帝祈祷,然后向我所能想到的其他相关神灵祈祷,但仍然 – 没有.

它可能只是对第二组眼睛的尖叫需求,但任何想法?

import UIKitimport UserNotificationsimport Firebaseimport FirebaseMessaging@UIApplicationMainclass AppDelegate: UIResponder,UIApplicationDelegate {    var window: UIWindow?    let gcmMessageIDKey = "gcm.message_ID"    func application(_ application: UIApplication,dIDFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {        FIRApp.configure()        // OverrIDe point for customization after application launch.        // OverrIDe point for customization after application launch.        // [START register_for_notifications]        if #available(iOS 10.0,*) {            let authOptions : UNAuthorizationoptions = [.alert,.badge,.sound]            UNUserNotificationCenter.current().requestAuthorization(                options: authOptions,completionHandler: {_,_ in })            // For iOS 10 display notification (sent via APNS)            UNUserNotificationCenter.current().delegate = self            // For iOS 10 data message (sent via FCM)            FIRMessaging.messaging().remoteMessageDelegate = self        } else {            let settings: UIUserNotificationSettings =                UIUserNotificationSettings(types: [.alert,.sound],categorIEs: nil)            application.registerUserNotificationSettings(settings)        }        application.registerForRemoteNotifications()        // Add observer for InstanceID token refresh callback.        NotificationCenter.default.addobserver(self,selector: #selector(self.tokenRefreshNotification),name: NSNotification.name.firInstanceIDTokenRefresh,object: nil)        return true    }    func tokenRefreshNotification(_ notification: Notification) {        if let refreshedToken = FIRInstanceID.instanceID().token() {            print("InstanceID token: \(refreshedToken)")        }        // Connect to FCM since connection may have Failed when attempted before having a token.        connectToFcm()    }    // [START connect_to_fcm]    func connectToFcm() {        FIRMessaging.messaging().connect { (error) in            if error != nil {                print("Unable to connect with FCM. \(error)")            } else {                print("Connected to FCM.")            }        }    }    // [END connect_to_fcm]    func applicationWillResignActive(_ application: UIApplication) {        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the Transition to the background state.        // Use this method to pause ongoing tasks,disable timers,and invalIDate graphics rendering callbacks. Games should use this method to pause the game.    }    func applicationDIDEnterBackground(_ application: UIApplication) {        // Use this method to release shared resources,save user data,invalIDate timers,and store enough application state information to restore your application to its current state in case it is terminated later.        // If your application supports background execution,this method is called instead of applicationWillTerminate: when the user quits.    }    func applicationWillEnterForeground(_ application: UIApplication) {        // Called as part of the Transition from the background to the active state; here you can undo many of the changes made on entering the background.    }    func applicationDIDBecomeActive(_ application: UIApplication) {        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was prevIoUsly in the background,optionally refresh the user interface.    }    func applicationWillTerminate(_ application: UIApplication) {        // Called when the application is about to terminate. Save data if appropriate. See also applicationDIDEnterBackground:.    }    func application(_ application: UIApplication,dIDReceiveRemoteNotification userInfo: [AnyHashable: Any]) {        // If you are receiving a notification message while your app is in the background,// this callback will not be fired till the user taps on the notification launching the application.        // Todo: Handle data of notification        // Print message ID.        if let messageID = userInfo[gcmMessageIDKey] {            print("Message ID: \(messageID)")        }        // Print full message.        print(userInfo)    }    private func application(application: UIApplication,dIDRegisterForRemoteNotificationsWithDevicetoken devicetoken: NSData) {//        let tokenChars = devicetoken.bytes        var tokenString = ""        for i in 0..<devicetoken.length {            tokenString += String(format: "%02.2hhx",arguments: [[devicetoken.bytes as! CVararg][i]])        }        FIRInstanceID.instanceID().setAPNSToken(devicetoken as Data,type: FIRInstanceIDAPNSTokenType.unkNown)        print("tokenString: \(tokenString)")    }}

以下是扩展……

import Foundationimport UserNotificationsimport FirebaseMessaging@available(iOS 10,*)extension AppDelegate : UNUserNotificationCenterDelegate {    // Receive displayed notifications for iOS 10 devices.    func userNotificationCenter(_ center: UNUserNotificationCenter,willPresent notification: UNNotification,withCompletionHandler completionHandler: @escaPing (UNNotificationPresentationoptions) -> VoID) {        let userInfo = notification.request.content.userInfo        // Print message ID.        print("Message ID: \(userInfo["gcm.message_ID"]!)")        // Print full message.        print("%@",userInfo)    }}extension AppDelegate : FIRMessagingDelegate {    // Receive data message on iOS 10 devices.    func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) {        print("%@",remoteMessage.appData)    }}

令牌正在登录控制台,FCM已连接,云消息传递正在保存我的证书…我可能唯一可能的提示是Firebase控制台不会将发送消息的设备计为“已发送”.


但控制台看起来很好.

2016-12-15 00:07:05.344 voltuser[4199:2008900] WARNING: Firebase Analytics App Delegate Proxy is Disabled. To log deep link campaigns manually,call the methods in FIRAnalytics+AppDelegate.h.2016-12-15 00:07:05.349 voltuser[4199:2008900] Firebase automatic screen reporting is enabled. Call +[FIRAnalytics setScreenname:setScreenClass:] to set the screen name or overrIDe the default screen class name. To disable automatic screen reporting,set the flag FirebaseautomaticScreenReportingEnabled to NO in the Info.pList2016-12-15 00:07:05.447 voltuser[4199] <DeBUG> [Firebase/Core][I-COR000001] Configuring the default app.2016-12-15 00:07:05.514: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iID Code=1001 "(null)"2016-12-15 00:07:05.520: <FIRMessaging/INFO> FIRMessaging library version 1.2.02016-12-15 00:07:05.549 voltuser[4199:] <FIRAnalytics/INFO> Firebase Analytics v.3600000 started2016-12-15 00:07:05.549 voltuser[4199:] <FIRAnalytics/INFO> To enable deBUG logging set the following application argument: -FIRAnalyticsDeBUGEnabled (see this)2016-12-15 00:07:05.605 voltuser[4199] <DeBUG> [Firebase/Core][I-COR000018] Already sending logs.2016-12-15 00:07:05.679 voltuser[4199] <DeBUG> [Firebase/Core][I-COR000019] Clearcut post completed.2016-12-15 00:07:05.782 voltuser[4199] <DeBUG> [Firebase/Core][I-COR000019] Clearcut post completed.2016-12-15 00:07:05.824 voltuser[4199:] <FIRAnalytics/WARNING> The AdSupport Framework is not currently linked. Some features will not function properly. Learn more at here2016-12-15 00:07:07.286 voltuser[4199:] <FIRAnalytics/INFO> Firebase Analytics enabledInstanceID token: c_4iSvTQcHw:APA91bGjKnPoH9LysKl9CQxCJRJsfqwXBSUFAmgRp-KEWKjWqe2j4nt6Y5gx8us41rB6eLnRCOwRntnbr_N1fh_swz8j-GvvChSsV3gvG8dufVFLpagdtOxrxPSglubQrfw-JqkA-4wVConnected to FCM.And the snapshot says Snap (mx7zr3y6XpSGZ4uB4PhZ8QRHIvt2) <null>[AnyHashable("notification"): {    body = "THIS IS SO PAINFul";    e = 1;    Title = "WHY WONT YOU WORK";},AnyHashable("from"): 99570566728,AnyHashable("collapse_key"): com.mishastone.voltuser]

…但是消息在我的控制台中正常记录.事实上,根本没有出现错误的错误!

我的手机没有从应用程序获得前景,背景或任何类型的通知 – 没有任何东西.压缩.小人物.纳达.只是我心碎的声音.

我的iPhone目前是9.3.5.如果这有帮助.

任何帮助将不胜感激 – 或建议替代推送通知系统……

解决方法 弄清楚了.
附:我使用Swift 3语法,你缺少willPresent方法中的completionhandler

completionHandler
The block to execute with the presentation option for the notification. Always execute this block at some point during your implementation of this method.

https://developer.apple.com/reference/usernotifications/unusernotificationcenterdelegate/1649518-usernotificationcenter

func userNotificationCenter(_ center: UNUserNotificationCenter,withCompletionHandler completionHandler: @escaPing (UNNotificationPresentationoptions) -> VoID) {    let userInfo = notification.request.content.userInfo as! [String: Any]    completionHandler([.alert,.sound])}
总结

以上是内存溢出为你收集整理的ios – FCM Swift 3 – 没有出现通知全部内容,希望文章能够帮你解决ios – FCM Swift 3 – 没有出现通知所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1108107.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存