2012-07-24 34 views
2

我正在嘗試創建鏈接到iOS中的我的Twitter配置文件的URL協議。但是如果用戶沒有安裝Twitter應用程序,我希望它可以回退到Safari。我會怎麼做?這是我使用的是現在的代碼:我相信,如果你可以測試將URL協議捕獲到未安裝的應用程序

NSString *stringURL = @"twitter://user?screen_name=ecnepsnai"; 
NSURL *url = [NSURL URLWithString:stringURL]; 
[[UIApplication sharedApplication] openURL:url]; 

回答

2

你可以使用的方法-canOpenURL:UIApplication

NSString *stringURL = @"twitter://user?screen_name=ecnepsnai"; 
NSURL *url = [NSURL URLWithString:stringURL]; 

if ([[UIApplication sharedApplication] canOpenURL:url]) { 
    [[UIApplication sharedApplication] openURL:url]; 
} else { 
    // Do something else 
} 
3

「推特://」網址都可以使用的處理方式:

if ([[UIApplication sharedApplication] canOpenURL:url]) { 
    [[UIApplication sharedApplication] openURL:url]; 
} else { 
    // fallback 
} 
相關問題