0
好吧,我有一個應用程序,我想要實現推送通知。問題是我想用用戶名來幫助確定他們發送通知的設備。但是當它在代理中被調用時,用戶還沒有登錄,所以應用程序崩潰。代碼是用這種方法從外部應用程序代理調用推送通知註冊
- (void)applicationDidBecomeActive:(UIApplication *)application
{
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
currentInstallation[@"installationUser"] = [[PFUser currentUser]username];
// here we add a column to the installation table and store the current user’s ID
// this way we can target specific users later
// while we’re at it, this is a good place to reset our app’s badge count
// you have to do this locally as well as on the parse server by updating
// the PFInstallation object
if (currentInstallation.badge != 0) {
currentInstallation.badge = 0;
[currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
// Handle error here with an alert…
}
else {
// only update locally if the remote update succeeded so they always match
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
NSLog(@"updated badge");
}
}];
}
}
所以我需要這個不被調用,如果用戶還沒有登錄,但然後我希望它被調用每次。我對如何做到這一點感到困惑。如果您有任何想法,請告知我,謝謝!
查看我的回答供審閱。最好把它放在viewDidAppear方法中的主視圖控制器中。確保設置了所有的通知標記並正確調用了方法。以下是其他人查看的文檔:https://parse.com/tutorials/login-and-signup-views – soulshined 2014-12-05 00:29:07
我回答了您的問題嗎?如果是這樣,請讓我相信正確的答案 – soulshined 2014-12-05 18:41:53