CancelAllLocalNotifications有时不工作

时间:2015-10-21 13:28:15

标签: ios

每当我的应用程序进入后台时,我首先调用 [[UIApplication sharedApplication] cancelAllLocalNotifications]; 。然后我根据需要重新安排本地通知。

但有时很久以前安排的本地通知应该被取消仍然被解雇。我将创建时间放在每个本地通知的userinfo中。在 didReceiveLocalNotification:(UILocalNotification *)通知方法中,我获得此通知的创建时间。并且在此之后调用了cancelAllLocalNotifications。所以我100%肯定这个通知应该被取消。它是如此有线,它仍然被解雇!

我的应用程序在iOS9.0.2上测试过。有没有人有类似的问题?

1 个答案:

答案 0 :(得分:0)

使用这种方式逐个删除应用的本地通知。它正常工作,完全按照你的意愿。

var xhr = new XMLHttpRequest();
xhr.responseType = 'blob'; //so you can access the response like a normal URL
xhr.onreadystatechange = function () {
    if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
        var img = document.createElement('img');
        img.src = URL.createObjectURL(xhr.response); //create <img> with src set to the blob
        document.body.appendChild(img);
    }
};
xhr.open('GET', 'http://images.example.com/my_secure_image.png', true);
xhr.setRequestHeader('SecretPassword', 'password123');
xhr.send();