【发布时间】:2017-07-20 04:40:09
【问题描述】:
我是 Swift 新手,iOS 10 中没有弹出推送通知,我做了所有配置。通知在 iOS 8 和 9 设备中显示(相同代码),但在 iOS 10 设备中不显示。代码就像(只添加了通知部分代码)。
private let brandFullery : String = "some token key"
var pushNotify : NSDictionary!
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
UIApplication.sharedApplication().cancelAllLocalNotifications()
MyCacheManager.sharedInstance.deviceId = UIDevice.currentDevice().identifierForVendor!.UUIDString
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Sound, .Alert, .Badge], categories: nil))
application.registerForRemoteNotifications()
MyCacheManager.sharedInstance.deleteAllFileInDocument("LiveUserProfile")
if let payload = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary, metData = payload["data"] as? NSDictionary {
pushNotify = metData
let aps = pushNotify["eventType"] as! NSString
if aps != "INVITE_POINTS" && aps != "UPDATE_BEACON" && aps != "CREATE_REWARD" {
MyCacheManager.sharedInstance.isFromNotification = aps as String
} else {
if aps == "UPDATE_BEACON" {
MyCacheManager.sharedInstance.isBeaconUpdate = true
}
MyCacheManager.sharedInstance.isFromNotification = ""
}
self.createMenuView()
} else {
MyCacheManager.sharedInstance.isFromNotification = ""
self.createMenuView()
}
#if BRANDAPP
Twitter.sharedInstance().startWithConsumerKey(brandTwitterAuthKey, consumerSecret: brandSecuriteKey)
Flurry.startSession(brandFullery)
#else
Twitter.sharedInstance().startWithConsumerKey(userTwitterAuthKey, consumerSecret: userSecuriteKey)
Flurry.startSession(userFullery)
#endif
Fabric.with([Twitter.self])
UIApplication.sharedApplication().statusBarStyle = .LightContent
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
//MARK: Push notification
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
var deviceTokenString : NSString = deviceToken.description;
deviceTokenString = deviceTokenString.stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString: "<>"))
deviceTokenString = deviceTokenString.stringByReplacingOccurrencesOfString(" ", withString: "")
MyCacheManager.sharedInstance.deviceToken = deviceTokenString as String
MyCacheManager.sharedInstance.putDeviceToken(deviceTokenString)
NSLog("device %@", deviceTokenString)
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
MyCacheManager.sharedInstance.isFromNotification = "MSG"
print(userInfo)
}
请任何人帮助我完成这项工作。非常感谢。
【问题讨论】:
-
您必须为 iOS 10 使用更新的 API,即
UNUserNotificationCenter。请参考stackoverflow.com/questions/37807302/…
标签: ios swift push-notification apple-push-notifications ios10