【问题标题】:ios - SWRevealViewController segue to last view in navigation controller when receive push notificationios - SWRevealViewController 在收到推送通知时转到导航控制器中的最后一个视图
【发布时间】:2015-05-28 15:12:09
【问题描述】:

我在我的项目中使用 SWRevealViewController 2.3.0。我的故事板设计如下: http://i.stack.imgur.com/txv0G.png

当应用程序没有运行(完全终止)并且推送通知来时,如何让 Detail view controller 显示一个 Back 按钮返回 主视图控制器?一些通知值应该已传递到详细信息视图。

感谢您的帮助。

【问题讨论】:

    标签: push-notification segue appdelegate swrevealviewcontroller


    【解决方案1】:

    在这种情况下我正在做的是

    你可以检查launchOptions是否不为零didFinishLaunchingWithOptions

    if (launchOptions)
    {
        NSDictionary *dic = [launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
        [[NSUserDefaults standardUserDefaults] setObject:[dic objectForKey:@"aps"] forKey:@"PushNotification"];
    }
    else
    {
        [[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"PushNotification"];
    }
    

    并像我一样保存在用户默认值中。

    现在只需当您在mainViewController 时,您可以将其检查为

    NSDictionary *notification = [[NSUserDefaults standardUserDefaults] objectForKey:@"PushNotification"];
    
    if (notification)
    {
        // check the dictionary "Push Notification" Key Values that you are receiving to go in `DetailViewController` 
        // Now go to `DetailViewContoller` having your details from `PushNotification`by `performSegueWithIdentifier`
    
        [self performSegueWithIdentifier:@"DetailViewController" sender:self];
    
        // make this value nil for normal use 
        [[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"PushNotification"];
    }
    

    如果你这里没有把这个userDefaults的值设为nil,你也可以在DetailViewController中使用它,但不要忘记使用后设为nil。

    使用这种方式,您的 BACK 按钮应该会显示在 DetailViewController 中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-12
      • 1970-01-01
      • 1970-01-01
      • 2016-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多