[英]Update badge of icon and get the message of notification when the icon is clicked
i try to update the badge of icon every time when a push notification arrives and when i click the icon i want to get the message of notification. 我尝试在每次推送通知到达时和单击图标时都更新图标的徽章,我想获取通知消息。
For badge i tried to use a local notification in "applicationDidReceiveRemoteNotifications": 对于徽章,我尝试在“ 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];
and that 然后
[UIApplication sharedApplication].applicationIconBadgeNumber += 1; [UIApplication sharedApplication] .applicationIconBadgeNumber + = 1;
None of them works. 它们都不起作用。
To get the message of notification by clicking the icon is even harder 通过单击图标来获取通知消息更加困难
Thanks in advance 提前致谢
this works fine in my project: 这在我的项目中工作正常:
- (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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.