2016-01-11 63 views
0

我是一個試圖在解析中使用推送通知的客觀c編碼器。解析推送通知測試PFInstallation不起作用

我在appDelegate.m文件的didFinishLaunchingWithOptions部分添加了Parse setApplicationID和Client Key。然後,我添加了這兩種方法:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 

// Store the deviceToken in the current installation and save it to Parse. 
PFInstallation *currentInstallation = [PFInstallation currentInstallation]; 
[currentInstallation setDeviceTokenFromData:deviceToken]; 
currentInstallation.badge = 0; 
NSArray *channels = [NSArray arrayWithObjects:@"global", [DataSource sharedInstance].userProfile.userID, nil]; 
[currentInstallation addObjectsFromArray:channels forKey:@"channels"]; 
[currentInstallation saveInBackground]; 
} 

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
[PFPush handlePush:userInfo]; 
} 

每當currentInstallation.badge數量的變化,對應用程序的徽章數量的響應,當我突破點的代碼,它表明的通道已被添加到currentInstallation。

問題是當前安裝未保存在Parse數據庫的Core Installation對象部分。我添加到currentInstallation的通道在saveInBackground運行後不會顯示。

在調試問題時,我刪除了Core Installation數據庫中與我用於測試的設備(這是Core Installation數據庫中唯一對象)對應的行。當我重新運行代碼時,什麼都不會被添加。

還有一點信息是我很確定我正確地完成了所有設置,因爲在完成所有設置後,我能夠在設備上接收測試推送通知。問題是我無法以編程方式更改我的測試設備在Core安裝數據庫上訂閱的頻道。

所以基本上我的問題是:如何使用PFInstallation saveInBackground將項目寫入Core Installation數據庫?我究竟做錯了什麼?

感謝您的幫助!對此,我真的非常感激!

編輯 還有一個問題,現在,是我不能添加我測試推送通知回我的Core安裝的設備對象的數據庫,所以我仍然在0對象數據庫。有關我如何恢復的任何建議?

+0

嘗試改爲'PFPush subscribeToChannelInBackground:'。您可能還需要刪除該應用程序並重新安裝它 – Wain

+0

@您是說通過刪除應用程序並重新安裝它意味着什麼?在Parse中刪除它? –

+0

不,來自設備 – Wain

回答

0

這太令人沮喪了。我所要做的就是註銷我的Parse帳戶,然後重新登錄。瞧!渠道在那裏!