如何在iOS中清除推送通知

时间:2013-04-02 13:36:52

标签: ios objective-c push-notification apple-push-notifications

有没有办法在iOS中取消/清除推送通知? (我知道[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]返回字典而不是Notification对象。)

APN是否有类似于本地通知的内容,请致电:

  1. [[UIApplication sharedApplication] cancelLocalNotification:notification];用于清除一条通知。

  2. 所有本地通知的
  3. [[UIApplication sharedApplication] cancelAllLocalNotifications];。 ??

  4. 早些时候(在应用程序的上一版本中)APN在点击它们时被清除。 但是,现在他们还没有被清除。我只是不明白为什么?

    “分配”配置文件中的“权利”键如下所示:

    <key>Entitlements</key>
    <dict>
        <key>application-identifier</key>
        <string>74T2SKP33D.com.xyz.abc</string>
        <key>aps-environment</key>
        <string>production</string>
        <key>com.apple.developer.default-data-protection</key>
        <string>NSFileProtectionComplete</string>
        <key>get-task-allow</key>
        <false/>
        <key>keychain-access-groups</key>
        <array>
            <string>74T2SKP33D.*</string>
        </array>
    </dict>
    

    我正在使用ad-hoc配置文件并通过testflight分发应用程序。

3 个答案:

答案 0 :(得分:1)

[[UIApplication sharedApplication] unregisterForRemoteNotifications]; 

会为你做到这一点。

答案 1 :(得分:0)

将应用的徽章编号设置为零将删除通知中心的所有推送通知,并清除图标徽章。

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

答案 2 :(得分:-1)

您可以使用cancelAllNotifications。看看

UIApplication Class Reference : cancelAllLocalNotifications

希望这有帮助。