我正在尝试使用Parse在测试项目上设置推送通知。
我已按照推送设置教程/指南进行操作。
我已在Parse仪表板中启用客户端推送。
我已更新.plist
我已在目标和项目的构建设置中设置了代码签名设置。
我发送推文:
PFPush.sendPushMessageToChannelInBackground("global", withMessage: "First push ever") { (success: Bool!, error: NSError!) -> Void in
...
}
当我尝试发送推送时,我收到以下错误
Error Domain=Parse Code=115 "The operation couldn’t be completed. (Parse error 115.)" UserInfo=0x1764cad0 {code=115, error=Client-initiated push isn't enabled.}
这
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError)
我是否错误地设置了配置文件和证书?有没有办法检查这个?我是否在appDelegate中错误地设置了Parse?有没有办法检查这个?
我的应用代表看起来像这样:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Parse.setApplicationId("xxx", clientKey: "xxx")
var userNotificationTypes = (UIUserNotificationType.Alert | UIUserNotificationType.Badge)
var settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
return true
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
var currentInstallation = PFInstallation.currentInstallation()
currentInstallation.setDeviceTokenFromData(deviceToken)
currentInstallation.channels = ["global"]
currentInstallation.save()
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
if error != nil {
println(error)
}
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
PFPush.handlePush(userInfo)
}
func applicationDidBecomeActive(application: UIApplication) {
var currentInstallation = PFInstallation.currentInstallation()
if currentInstallation.badge != 0 {
currentInstallation.badge = 0
currentInstallation.saveEventually()
}
答案 0 :(得分:1)
您不会从应用代理发送客户推送。您从触发推送的操作发送它们。
这是Objective C中的一个例子:
// Create our Installation query
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"channels" equalTo:@"Giants"]; // Set channel
[pushQuery whereKey:@"scores" equalTo:YES];
// Send push notification to query
PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery];
[push setMessage:@"Giants scored against the A's! It's now 2-2."];
[push sendPushInBackground];
而且,如果您计划将此应用程序发送到应用程序商店,您应该使用云代码来处理客户端推送,因为直接客户端到客户端会将您的应用程序推向安全漏洞。