2014-11-04 40 views
0

我尝试每次推送通知到达时都更新图标的徽章,当我点击图标时我想要获取通知消息。更新图标的徽章,并在单击图标时获取通知消息

对于徽章我试图在 “applicationDidReceiveRemoteNotifications” 为使用本地通知:

UILocalNotification * setBadge = [[UILocalNotification alloc] init]; 

    UIApplication * app = [UIApplication sharedApplication]; 

    setBadge.timeZone = [NSTimeZone defaultTimeZone]; 

    // Update the badge of app when a notif appears 
    setBadge.applicationIconBadgeNumber += 1; 

    setBadge.fireDate = [NSDate dateWithTimeIntervalSinceNow:2]; 

    [app scheduleLocalNotification:setBadge]; 

[UIApplication的sharedApplication] .applicationIconBadgeNumber + = 1;

没有一个可行。

通过点击图标来获取通知的消息更是难上加难提前

回答

0

能正常工作在我的项目

感谢:

- (void)applicationDidBecomeActive:(UIApplication *)application 
{ 
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
    self.isBackground = NO; 
    [[NSNotificationCenter defaultCenter] postNotificationName:AppChangeState object:@(self.isBackground)]; 
    [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:DID_BECOME_ACTIVE 
                         object:nil 
                         userInfo:nil]]; 

    [UIApplication sharedApplication].applicationIconBadgeNumber = 0; 
} 
+0

你放什么地方了“的addObserver”? – Developer3000 2014-11-04 17:33:31