对于ios 10,我使用它来注册推送通知:
有没有办法在appdelegate和func应用程序之外请求requestAuthorization(options [.badge,.alert,.sound])(_ application:UIApplication,didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?)-> Bool
我问的原因是因为我不想在用户使用应用程序一段时间后显示弹出式通知推送消息。有任何想法吗?
就像@dan 说的,没有必要在AppDelegate. 您可以随心所欲地进行。这就是您可能正在为此做的事情。
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .badge, .sound]) { (success, error) in
if error == nil {
if success {
print("Permission granted")
// In case you want to register for the remote notifications
let application = UIApplication.shared
application.registerForRemoteNotifications()
} else {
print("Permission denied")
}
} else {
print(error)
}
}
Run Code Online (Sandbox Code Playgroud)
并记住
UserNotifications使用此代码的框架。didRegisterForRemoteNotificationsWithDeviceToken在您的AppDelegate| 归档时间: |
|
| 查看次数: |
2252 次 |
| 最近记录: |