如何从通知区域删除特定的远程通知
问题描述:
我想搜索特定的推送通知并将其从通知区域中删除。我想要一个看起来像这样的代码,除了它应该用于远程通知而不是本地通知。提前致谢。如何从通知区域删除特定的远程通知
for (UILocalNotification *lNotification in [[UIApplication sharedApplication] scheduledLocalNotifications])
{
if (![[userRecord valueForKey:@"User"] isEqualToString:[userInfo objectForKey:@"User"]])
{
[[UIApplication sharedApplication] cancelLocalNotification:lNotification];
}
}
答
如果我理解你正确 - 你想跳过你的客户端的一些远程通知。 你不能那样做。 您的远程通知是从苹果服务器(通常通过您的服务器)发送并传送到iOs系统,然后它会通过iPhone或iWatch传送到您的应用程序。 在应用程序,你可以使用:
@available(iOS 8.0, *)
public func registerForRemoteNotifications()
@available(iOS 3.0, *)
public func unregisterForRemoteNotifications()
@available(iOS 8.0, *)
public func registerUserNotificationSettings(notificationSettings: UIUserNotificationSettings)
@available(iOS 8.0, *)
public func currentUserNotificationSettings() -> UIUserNotificationSettings?
你应该让自己从自己的服务器发送远程推的逻辑。
答
在
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
if ([[userInfo objectForKey:@"User"] isEqualToString:@"Your user"])
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
//Do Nothing
return;
}
else
{
//process according to need
}
}
远程通知从服务器sended,因此它可以在接收端或服务器从仅end.I控制是希望这会有所帮助。
我想到了这一点,但这将删除所有的通知,如果我没有错。 – Nitin
不,你应该使用这行代码来处理需要通知,如if([[userInfo objectForKey:@“User”] isEqual:@“Your user”]) – baydi