2015-01-15 52 views
0

我想在測試項目上設置Parse推送通知。如何設置分析客戶端推送通知

我遵循了推送設置教程/指南。

我已啓用客戶端推送在Parse儀表板。 enter image description here

我已經更新了的.plist

我已經設定了目標和項目生成設置代碼簽名設置。

我通過發推:

PFPush.sendPushMessageToChannelInBackground("global", withMessage: "First push ever") { (success: Bool!, error: NSError!) -> Void in 
... 
} 

當我嘗試從

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) 

有無設置我的配置配置文件和發送推我收到以下錯誤

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.} 

證書不正確?有沒有辦法檢查這個?我有沒有設置錯誤地解析appDelegate?有沒有辦法檢查這個?

我的應用程序委託是這樣的:

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

你如何發送推送通知?我還沒有開始使用Swift,但看着你的代碼,我沒有看到你從客戶端發送推送通知的位置。如果您的應用向其他設備發送推送通知,則只需激活「啓用客戶端推送」即可。 – 2015-01-15 18:44:56

+0

我已更新問題以包含推送請求 – grabury 2015-01-15 19:53:32

+0

錯誤115表示推送在服務器上配置錯誤。你在Parse上配置了你的證書嗎?他們是正確的類型(開發與產品)?解析應該在推送區域告訴你你上傳了哪種類型的證書 - 確保你的應用程序版本使用相同的類型。 – rickerbh 2015-01-18 23:04:10

回答

1

你不要把客戶從應用程序的委託推動。您從觸發推送的操作中發送它們。

這裏是在目標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]; 

,僅供參考,如果你在航運這個程序的應用程序商店計劃,你應該使用雲代碼來處理客戶端的推動,因爲直接客戶端到客戶端會將您的應用程序推到安全漏洞。

相關問題