我尝试实施推送。我有以下代码
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if application.applicationState != UIApplicationState.Background {
// In that case, we skip tracking here to avoid double counting the app-open.
let preBackgroundPush = !application.respondsToSelector("backgroundRefreshStatus")
let oldPushHandlerOnly = !self.respondsToSelector("application:didReceiveRemoteNotification:fetchCompletionHandler:")
var pushPayload = false
if let options = launchOptions {
pushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil
}
if (preBackgroundPush || oldPushHandlerOnly || pushPayload) {
PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
}
}
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)
}
}
订阅我在viewDidLoad
let currentInstallation = PFInstallation.currentInstallation()
currentInstallation.addUniqueObject("Giants", forKey: "channels")
currentInstallation.saveInBackground()
问题是,当我发送推送时,只有一个设备接收它。出于测试目的,我将第二个设备连接到Xcode,但它没有收到推送消息。
对于设置我使用了开发证书。
开发证书是否有任何限制或我做错了什么?
答案 0 :(得分:1)
这里有一些你应该记住的事情。
现在,如何看出可能出现问题的地方。
检查通道的安装文件。您应该看到一个名为channels的列,您应该在这两个设备上都有Giants。如果没有出现问题,那么您只针对一台设备。要修复此错误,您只需删除该应用或手动添加Channels
密钥
您可能遇到的另一个错误是拒绝了发送推送通知的权限。确保在第二台设备上启用了此功能。要做到这一点,请转到设置 - >通知 - > "您的应用名称" - >将允许通知切换为开启。并选择横幅。
希望有帮助,朱利安