3

我在 Xcode 4.3.2 中工作

我实现Local Notifications了在预定时间提醒用户新事件。因此,当我的应用程序在后台并且时钟敲响时(例如)上午 8 点,用户将收到来自我的应用程序的通知。

当用户决定从后台查看应用程序时,我会加载一个 nib。目前,这个笔尖工作正常:它显示了它在笔尖中排列的视图。但是,在向用户显示 nib 后,我想将用户转发到LocalNotificationsHandler.m. 当我尝试推送第二个视图时,我的应用程序失败。因此,虽然没有错误消息,但似乎第二个笔尖不会加载。

简而言之,流程如下:

  • 当我的应用在后台运行时,用户会收到通知
  • 用户选择查看应用
  • LocalNotificationsHandler nib加载
  • self.navigationController == nil(在 LocalNotificationsHandler.m 中)
  • self.navigationController 不会 "[pushViewController: "new view" animated:YES]" 获取新视图

我想知道我的 AppDelegate.m 文件中是否缺少某些内容,因此我在 AppDelegate.m 文件中包含了“didFinishLaunchingWithOptions”:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    // Add the navigation controller's view to the window and display.


    NSLog(@"did finish launching with options");
    [self.window addSubview:tabBarController.view];
    [self.window makeKeyAndVisible];

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

  if (self.locationManager == nil)
  {
    locationManager = [[CLLocationManager alloc] init];
    locationManager.purpose = @"We will try to use you location";
  }

  if([CLLocationManager locationServicesEnabled])
  {
    [self.locationManager startUpdatingLocation];
  }

  self.navigationController.navigationBar.tintColor = nil;

  return YES;
}
4

1 回答 1

1

您正在使用过时的(自 iOS 3 起)将 viewcontroller 的视图添加到主 UIWindow 的方法。那应该是这样的:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // create properly sized window
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // create instance of root VC and assign to window
    MainViewController *vc = [[MainViewController alloc] init];
    self.window.rootViewController = vc;
    [vc release];

    [self.window makeKeyAndVisible];

    return YES;
}

只有当它实际上是从 UINavigationController 呈现时,才会设置视图控制器的 navigationController 属性。

有关更多信息,请参阅此文章:http: //www.cocoanetics.com/2012/11/revisited/

于 2013-01-05T07:50:06.137 回答