模拟启动选项

7
在我的appDelegate中,当应用程序从i.e.邮件应用程序启动时,我有一些规格要求。
当我启动我的应用程序时,一切正常。当我通过邮件中的文件启动应用程序时,它会崩溃。不幸的是,我无法调试它,因为我无法模拟launchingOptions。 目前,我构建和运行,然后断开iPad,关闭我的应用程序,然后转到邮件等... 有没有一种方法可以进行调试?

Appdelegate.m

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

NSURL *url = (NSURL *)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];

IntroViewController *introViewController = (IntroViewController *)self.window.rootViewController;

if (url !=nil) {
    if ([url isFileURL]) {
        introViewController.fileUrl = url;
    }


}

NSLog(@"%@",[url path]);

return YES;
}

IntroViewController

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"Hello");
    if (fileUrl != nil) {
        IntroTableViewController* introTable = (IntroTableViewController *)segue.destinationViewController;            
        introTable.openedByURL = [fileUrl path];

        TabBarController* tabBarController = (TabBarController *)segue.destinationViewController;
        UINavigationController* navigationController = (UINavigationController *)[[tabBarController viewControllers] objectAtIndex:0];
        TargetLSController* targetViewController = (TargetLSController *)[[navigationController viewControllers] objectAtIndex:0];
        NSString *urlPath = [fileUrl path];
        targetViewController.currentFilePath = urlPath;
        NSLog(@"%@",urlPath);
    }
}

- (void)viewDidAppear:(BOOL)animated
{
    [self performSegueWithIdentifier:@"Launch" sender:self]; 
    NSLog(@"%@",fileUrl);
}

你还能在该设备的组织者窗口中看到控制台吗? - deanWombourne
我不确定您的意思是什么... - Faser
2
我的意思是你可以从“窗口->组织者”中看到NSLog的输出。然而,@fichek的答案比我的想法好多了 :) - deanWombourne
我甚至不知道有一个组织者部分可以查看日志!谢谢! - Faser
1个回答

19

(假设您使用Xcode 4.x)

产品 -> 编辑方案...运行 <应用程序名称>.app 下,第一个选项卡 (信息) 中有 启动 选项。选择 等待 <应用程序名称.app> 启动。现在当您执行构建和运行 (或者只运行) 时,调试器将等待您手动启动应用程序。


非常好,非常感谢!不幸的是,NSLog不再触发了吗? - Faser
1
你可能仍然可以在Mac OS X Console.app中看到NSLog的输出。或者,如果你正在运行设备上,你可能可以在Organizer >> Devices中看到它,插入一个设备,然后选择它的Console。 - Andrew Ebling

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接