我有一个iOS应用程序,其中发送了一些推送通知.我的问题是,在点击后,消息/通知会保留在iOS中的通知中心.下次应用程序打开时如何在通知中心删除我的应用程序通知?
我遇到过人们调用setApplicationIconBadgeNumber
零值来清除通知的帖子.这对我来说似乎很奇怪,所以我相信也许存在另一种解决方案?
EDIT1:
我在清除通知时遇到了一些问题.请在这里查看我的代码:
- (void) clearNotifications {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (launchOptions != nil)
{
NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
NSLog(@"Launched from push notification: %@", dictionary);
[self clearNotifications];
}
}
return YES;
}
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
NSLog(@"Received notification: %@", userInfo);
[self clearNotifications];
}
Run Code Online (Sandbox Code Playgroud)
我正在通过Xcode运行App.当应用程序最小化并且我使用通知中心中的通知启动应用程序时,我可以在日志didReceiveRemoteNotification
中看到,调用并使用我可以看到的断点,clearNotifications
已经运行了.但通知仍然在通知中心挂起.为什么?