ios – Swift 3 – Firebase推送通知,我该怎么办?

ios – Swift 3 – Firebase推送通知,我该怎么办?,第1张

概述我喜欢下面的 Swift 2.但它在 Swift 3中不起作用.我怎么能提供这个?如果有人解释这将是伟大的. didFinishLaunchingWithOptions let notificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)UIApplic 我喜欢下面的 Swift 2.但它在 Swift 3中不起作用.我怎么能提供这个?如果有人解释这将是伟大的.

dIDFinishLaunchingWithOptions

let notificationSettings = UIUserNotificationSettings(forTypes: [.Alert,.Badge,.sound],categorIEs: nil)UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)application.registerForRemoteNotifications()

func application(application: UIApplication,dIDRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {    if notificationSettings.types != .None {        application.registerForRemoteNotifications()    }}func application(application: UIApplication,dIDReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {    print("Meesage ID \(userInfo["gcm_message_ID"]!)")    print(userInfo)}

我可以做简单的本地通知,但是我无法从Firebase远程推送通知.

I trIEd

UNUserNotificationCenter.currentNotificationCenter().delegate = selfUNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions([.Alert,.sound]) { (success,error:NSError?) in        if success {            print("Notification access true!")            application.registerForRemoteNotifications()        }        else {            print(error?.localizedDescription)        }}

func application(application: UIApplication,dIDReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {    print("Meesage ID \(userInfo["gcm_message_ID"]!)")    print(userInfo)}

仍然无法正常工作.

解决方法 AppDelegate方法名称稍有变化,并引入了UserNotifications框架.您必须将此框架用于iOS 10及更高版本中的通知,因为其他方法已被弃用.

import UserNotifications...@UIApplicationMainclass AppDelegate: UIResponder,UIApplicationDelegate {    ...    func application(_ application: UIApplication,dIDFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {        UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.badge,.sound]) { (granted,error) in            // Enable or disable features based on authorization.        }        application.registerForRemoteNotifications()        return true    }    func application(_ application: UIApplication,dIDReceiveRemoteNotification userInfo: [AnyHashable : Any],fetchCompletionHandler completionHandler: @escaPing (UIBackgroundFetchResult) -> ()) {        print("Message ID \(userInfo["gcm.message_ID"]!)")        print(userInfo)    }    ...}

Registering for Push Notifications in Xcode 8/Swift 3.0?

总结

以上是内存溢出为你收集整理的ios – Swift 3 – Firebase推送通知,我该怎么办?全部内容,希望文章能够帮你解决ios – Swift 3 – Firebase推送通知,我该怎么办?所遇到的程序开发问题。

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

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

原文地址: https://outofmemory.cn/web/1007644.html

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

发表评论

登录后才能评论

评论列表(0条)

保存