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推送通知,我该怎么办?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)