我有一個與oneSignal作爲推送提供商的應用程序。我可以收到推送通知,這很好。但是,如果我嘗試訪問推送有效負載,則不會調用didReceiveRemoteNotification
。Swift didReceiveRemoteNotification不叫
我有下面的代碼
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if application.applicationState != UIApplicationState.Background {
let preBackgroundPush = !application.respondsToSelector("backgroundRefreshStatus")
let oldPushHandlerOnly = !self.respondsToSelector("application:didReceiveRemoteNotification:fetchCompletionHandler:")
var pushPayload = false
if let options = launchOptions {
pushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil
}
}
if application.respondsToSelector("registerUserNotificationSettings:") {
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
} else {
let types : UIRemoteNotificationType = [.Badge, .Alert, .Sound]
application.registerForRemoteNotificationTypes(types)
}
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
if userInfo["d"] as! String == "t" {
print("key was received")
}
print(userInfo)
print("PREVED")
}
問題是,沒有打印出來,當我收到推送。我究竟做錯了什麼 ?
委託方法被調用或不' –
委託方法不叫 –