Dev*_*ngh 5 iphone objective-c ios
我正在使用此代码。当推送通知出现时,一切正常,但当应用程序在后台时,徽章数量不会增加。如何解决这个问题呢?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
//UIApplication *application = [UIApplication sharedApplication];
NSInteger badgeNumber = [application applicationIconBadgeNumber];// Take the current badge number
//badgeNumber--; // decrement by one
[application setApplicationIconBadgeNumber:[[[launchOptions valueForKey:@"aps"]valueForKey:@"badge"]integerValue]]; // set ne badge number
NSLog(@"userInfo :%@ %d",launchOptions,[[[launchOptions valueForKey:@"aps"]valueForKey:@"badge"]integerValue]);
return YES;
}
Run Code Online (Sandbox Code Playgroud)
当应用程序处于后台时,该didFinishLaunchingWithOptions方法永远不会调用。要在应用程序处于后台时执行某些操作,您需要在AppDelegate's applicationDidEnterBackground: 方法中实现您的逻辑。
- (void)applicationDidEnterBackground:(UIApplication *)application{
[UIApplication sharedApplication].applicationIconBadgeNumber = 2;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12687 次 |
| 最近记录: |