簡體   English   中英

application:didReceiveLocalNotification:執行segue,並在取消segue之后再次調用

[英]application:didReceiveLocalNotification: performs segue, and gets called again after segue is dismissed

我的iOS應用正在安排本地通知,當用戶點擊時,它將通知用戶進入我應用中的指定視圖。 當我點擊通知時,應用會打開(它在后台),並且方法

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    application.applicationIconBadgeNumber = 0;
    [self handleNotification:notification];
}

-(void) handleNotification:(UILocalNotification *)notification
{
    NSString *type = [notification.userInfo objectForKey:NOTIFICATION_TYPE_KEY];
    if([type isEqualToString:TYPE_MESSAGE])
    {
        [self.window.rootViewController performSegueWithIdentifier:@"SeeMessagesSegue" sender:self];
    }
}

被稱為,因為他們應該。 依序執行segue,並帶我到正確的屏幕。 在此屏幕上,我有一個按鈕,可通過調用將我帶回到應用程序的根視圖控制器(主菜單)

[self dismissViewControllerAnimated:YES completion:nil];

視圖消失了,我回到主菜單,但是隨后再次調用application:didReceiveLocalNotification:方法,並再次執行segue。

為什么要再次調用該方法(如果不再次調用該視圖控制器,我永遠也無法解雇它),以及如何處理呢?

編輯:這是創建通知的代碼:

- (void)scheduleNotificationWithMessage:(Message *) msg
{
    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    if (localNotif == nil)
        return;
    localNotif.fireDate = msg.fireDate;
    localNotif.timeZone = [NSTimeZone defaultTimeZone];

    localNotif.alertBody = msg.text;
    localNotif.alertAction = NSLocalizedString(@"notification_open_text", nil);

    localNotif.soundName = UILocalNotificationDefaultSoundName;
    localNotif.applicationIconBadgeNumber = 1;

    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:msg.type forKey: NOTIFICATION_TYPE_KEY];
    localNotif.userInfo = infoDict;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}

問題是我在根視圖控制器的viewDidAppear中創建了一個新通知,並且由於該通知是及時的,因此它立即出現。

暫無
暫無

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

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