簡體   English   中英

iOS中未清除本地通知

[英]Local Notification is not clearing in iOS

我正在使用Beacon設備進行測試。 情況如下。 當接收者進入基於我手動設置的緯度和經度范圍的位置時,我會發出本地通知。 這工作正常,我正在didFinishLaunchingWithOptions上清除此通知。 當我進入下一個最近的區域時,我會收到通知,然后單擊它就可以顯示視圖。 但是,當我退出該應用程序時,本地通知不會被清除。 可能是什么問題?

我在兩個不同的區域使用兩種不同的方法。 第一個是

-(void) didEnterLocation:(SLMLocation*)location
{
// throwing a local notification
}

上面方法的通知正在清除

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
}

第二種方法如下:這是第二個區域

- (void) didEnterNewClosestRegion :(SLMBLERegion*) region
{
// throwing local notifications here & notifications are visible
}

現在,僅在第二種方法中,我無法清除本地通知。 非常感謝您的幫助。

這是因為didFinishLaunchingWithOptions方法僅在應用程序生命周期中被調用,它可能已經在后台運行,因此通知不會被清除。 我建議您將取消代碼移動到applicationDidBecomeActive

cancelAllLocalNotifications,取消所有預定的本地通知的傳遞,它不會從鎖屏或通知中心清除已經顯示的通知。

https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/UIApplication/cancelAllLocalNotifications

嘗試這個可能會有所幫助..

 - (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    [[UIApplication sharedApplication] cancelAllLocalNotifications];

}

謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM