2011-01-25 192 views

回答

18

您可以設置應用程序圖標的證件號碼這樣的:

[UIApplication sharedApplication].applicationIconBadgeNumber = 3; 
3

如果你想要把通過PUSH消息證件號碼,您可以發送PUSH爲:

{"aps":{"alert":"My Push Message","sound":"default","badge",3}} 

然後在您的AppDelegate中添加以下內容:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ 

// This get's the number you sent in the push and update your app badge. 
[UIApplication sharedApplication].applicationIconBadgeNumber = [[userInfo objectForKey:@"badge"] integerValue]; 

// Shows an alert in case the app is open, otherwise it won't notify anything 
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"New Notification!" 
               message:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] delegate:self 
               cancelButtonTitle:@"OK" 
               otherButtonTitles:nil]; 
[alertView show];  
} 
相關問題