2012-01-04 86 views
4

在我的appDelegate,我有一些規格,當應用程序啓動與文件從郵件應用程序。模擬啓動選項

當我啓動我的應用程序時,一切正常。當我通過郵件文件啓動應用程序時,應用程序崩潰。不幸的是,我無法調試它,因爲我無法模擬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); 
} 
+0

您是否仍然可以在該設備的Organizer窗口中看到控制檯? – deanWombourne 2012-01-04 11:04:08

+0

我不知道你的意思是什麼...... – Faser 2012-01-04 12:08:02

+2

我的意思是你可以看到NSLog從Window-> Organizer輸出的內容。不過,@ fichek的回答比我的想法更好:) – deanWombourne 2012-01-04 12:11:20

回答

12

(猜測你使用的Xcode 4.x版)

Product -> Edit Scheme...Run <appname>.app有在第一個選項卡Launch選項(Info)。選擇Wait for <appname.app>以啓動`。現在,當您執行構建&運行(或只是運行)時,調試器將等待您手動啓動應用程序。

+0

太好了,非常感謝!遺憾的是,沒有NSLog被解僱了? – Faser 2012-01-04 13:31:26

+1

您可能仍然能夠在Mac OS X Console.app中看到NSLog的輸出。或者,如果您在設備上運行,則可以在管理器>>設備中看到它,插入設備,然後選擇它的控制檯。 – 2012-09-21 14:37:43