我有一个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已经运行了.但通知仍然在通知中心挂起.为什么?
我想删除我的应用从iOS 5通知中心发出的旧通知.我可以这样做吗?如果是这样,怎么样?
是否可以在单击一个推送通知时从通知中心删除推送通知并启动应用程序?
大多数应用似乎都会留下通知.我读到另一个问题:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
Run Code Online (Sandbox Code Playgroud)
可能会工作,但它不适合我.
一旦点击,Facebook应用程序肯定会删除推送通知.
notifications apple-push-notifications ios notificationcenter