首先我们导入UserNotifications
框架
我们在AppDelegate.swift
class
if #available(iOS 10.0, *){
UNUserNotificationCenter.current().delegate = self
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
if (granted)
{
UIApplication.shared.registerForRemoteNotifications()
}
else{
//Do stuff if unsuccessful...
}
// Enable or disable features based on authorization.
}
}
答案 0 :(得分:-1)
请检查Target > Capabilities
下的“推送通知”开关:
将其打开