2011-01-25 31 views

Trả lời

18

Bạn có thể đặt số huy hiệu biểu tượng ứng dụng như thế này:

[UIApplication sharedApplication].applicationIconBadgeNumber = 3; 
3

Nếu bạn đang muốn đưa số huy hiệu qua tin nhắn PUSH, bạn có thể gửi PUSH như:

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

Sau đó, trong AppDelegate của bạn, bạn thêm thông tin sau:

- (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];  
} 
Các vấn đề liên quan