IOS 推送初始化后,后台预估人数为0
S沙城
发布于 4 年前
4260来自重庆消息推送 U-Push
API调用
没有执行下面的代码取到token
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
debugPrint("============deviceToken=====\(deviceToken)")
}
其余代码如下
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
UMCommonLogManager.setUp()
UMConfigure.setLogEnabled(true)
UMConfigure.initWithAppkey("xxx", channel: "App Store")
let entity = UMessageRegisterEntity()
entity.types = Int(UMessageAuthorizationOptions.badge.rawValue | UMessageAuthorizationOptions.alert.rawValue | UMessageAuthorizationOptions.sound.rawValue);
UNUserNotificationCenter.current().delegate = self
UMessage.registerForRemoteNotifications(launchOptions: launchOptions,entity: entity){ s , err in
debugPrint(s) //这里返回为true
}
return true
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo;
if(response.notification.request.trigger?.isKind(of:UNPushNotificationTrigger.self ) == true) {
UMessage.didReceiveRemoteNotification(userInfo)
}else{
//应用处于后台时的本地推送接受
}
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo;
if(notification.request.trigger?.isKind(of:UNPushNotificationTrigger.self) == true){
UMessage.setAutoAlert(false)
//必须加这句代码
UMessage.didReceiveRemoteNotification(userInfo)
}else{
//应用处于前台时的本地推送接受
}
}