Tag: unusernotificationcenter

Swift 4 – UIApplication.registerForRemoteNotifications()只能从主线程调用

Xcode 9(iOS 11)在注册Push(远程)通知时显示错误/警告。 这是错误信息 这里是代码,我试过了: let center = UNUserNotificationCenter.current() center.delegate = self center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in if error == nil{ UIApplication.shared.registerForRemoteNotifications() } } 错误/警告线: UIApplication.shared.registerForRemoteNotifications() 如何解决这个问题?

当应用程序处于前台时显示本地通知Swift 3

显然这是现在可以与ios10: optional func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) 这个答案基本上说,需要做的工具: 当应用程序打开并在前台显示股票iOS通知横幅? 我只是不太了解如何把它放在一起。 我不知道这是多么重要,但我不能保持可选的function和Xcode要我切换到私人。 我试图展示徽章和文档提供 static var badge: UNNotificationPresentationOptions { get } 有一点在这里丢失 然后我假设,如果我想排除某些视图控制器获得这些徽章,我不使用导航控制器,我发现这个代码将工作? :var window:UIWindow? if let viewControllers = window?.rootViewController?.childViewControllers { for viewController in viewControllers { if viewController.isKindOfClass(MyViewControllerClass) { print("Found it!!!") } } }

在Xcode 8 / Swift 3.0中注册推送通知?

我试图让我的应用程序在Xcode 8.0中工作,并且遇到错误。 我知道这个代码在以前版本的swift中工作得很好,但我假设在新版本中更改了代码。 这是我试图运行的代码: let settings = UIUserNotificationSettings(forTypes: [.Sound, .Alert, .Badge], categories: nil) UIApplication.sharedApplication().registerUserNotificationSettings(settings) UIApplication.shared().registerForRemoteNotifications() 我得到的错误是“参数标签”(forTypes :,类别:)“不匹配任何可用的重载” 有没有不同的命令,我可以尝试得到这个工作?