2014-06-18 49 views
2

我目前在獲取Parse(推送通知服務)在現有iOS應用程序上工作時遇到問題。具體而言, [PFInstallation currentInstallation]總是返回一個零值。在我didFinishLaunchingWithOptions方法我設置解析[PFInstallation currentInstallation]返回零

[Parse setApplicationId:parseAppID clientKey:parseClientKey]; 

但是,一旦我applicationDidRegisterForRemoteNotificationsWithDeviceToken方法被調用,下面返回代碼爲無currentInstallation。

PFInstallation *currentInstallation = [PFInstallation currentInstallation]; 
[currentInstallation setDeviceTokenFromData:_deviceToken]; 
[currentInstallation saveInBackground]; 

我不知道爲什麼試圖納入現有的應用程序時,這發生這種情況而已。我正在做一件與空白應用程序完全相同的事情,並且Parse在那裏完美地工作。請注意,沒有任何錯誤被拋出。我只需在[PFInstallation currentInstallation]上得到一個零回報,所以沒有任何保存。

任何幫助將非常感激。

回答

2

原來如果您在解析Web控制檯上刪除安裝這種情況。要解決它,你需要卸載並重新安裝你的手機上的應用程序,它應該再次開始工作。

+0

它不適用於我:( –

1

你應該做的第一件事就是用的「saveInBackgroundWithBlock」,而不是「saveInBackouground」:

[currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { 
    NSLog(@"success : %d with error : %@",succeeded,error); 
}]; 

這樣一來,你會看到,如果引發錯誤。

此外,在application:didFinishLaunchingWithOptions:方法,你也應該打個電話給

if ([[UIApplication sharedApplication] enabledRemoteNotificationTypes] != UIRemoteNotificationTypeNone) { 
    [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound]; 
} 

使得applicationDidRegisterForRemoteNotificationsWithDeviceToken方法每次啓動您的應用程序調用。

最後,你應該確保你已經鏈接這些庫到你的應用程序:

- AudioToolbox.framework 
- CFNetwork.framework 
- CoreGraphics.framework 
- CoreLocation.framework 
- libz.dylib 
- MobileCoreServices.framework 
- QuartzCore.framework 
- Security.framework 
- StoreKit.framework 
- SystemConfiguration.framework 
+0

Drico,感謝您的幫助。我確實已經讓我的應用程序註冊了不同的通知類型。而且我不認爲我的問題在原始問題中很明確。調用[PFInstallation currentInstallation]始終返回nil。所以當我在saveInBackground上發生錯誤時,我不相信這是問題。獲取當前安裝有些問題。我確實已將所有庫附加到我的應用程序 – user3684980

+0

噢好吧,我的錯誤。然後,如果您在didFinishLaunching方法中嘗試此操作,會發生什麼情況: [解析setApplicationId:parseAppID clientKey:parseClientKey]; NSLog(@「%@」,[PFInstallation currentInstallation]); //註冊後直接 – Drico