2012-01-23 3 views
21

내가 트위터 응용 프로그램을 사용하여 열려는 페이지 :내 아이폰 앱에서 트위터 앱에서 트위터 페이지를 여는 방법은 무엇입니까?

https://twitter.com/#!/PAGE

나는 다음과 같은 코드를 사용 트위터 앱을 열려면 :

NSURL *urlApp = [NSURL URLWithString: [NSString stringWithFormat:@"%@", @"twitter://https://twitter.com/#!/PAGE"]]; 
[[UIApplication sharedApplication] openURL:urlApp]; 

을하지만이 코드는하지 않는 것 예상대로 작동하고, 내가 보여주고 싶은 페이지없이 시작된 트위터 앱만 있습니다.

답변

38

다음 URL을 찾고 있습니다 : 트위터는 모든 장치에 설치되지 않았 음을

twitter:///user?screen_name=PAGE 

참고. openURL 방법의 결과를 확인해야합니다. 실패하면 Safari에서 일반 URL로 페이지를 엽니 다.

+4

스위프트 (3)에 대해 동일합니다 생각합니다. 2 개를 사용하면 나를 위해 일했습니다. –

14

나는이 질문에 대한 상당히 늦은 답변을 알고 있으며 Murat의 대답은 절대적으로 옳다는 것에 동의합니다. 다음과 같이 간단하게 검사를 추가

NSURL *urlApp = [NSURL URLWithString: [NSString stringWithFormat:@"%@", @"twitter:///user?screen_name=PAGE]]; 

if ([[UIApplication sharedApplication] canOpenURL:urlApp]){ 
     [[UIApplication sharedApplication] openURL:urlApp]; 
    } 

을 나는 희망이 사람을 도움이됩니다. 건배!! 당신은 그냥 할 응용 프로그램에서 트위터를 시작하는 방법을 알고 싶다면이 : : :

2

는 @Alexey

NSURL *urlApp = [NSURL URLWithString: [NSString stringWithFormat:@"%@", @"twitter://"]]; 
    if ([[UIApplication sharedApplication] canOpenURL:urlApp]){ 
     [[UIApplication sharedApplication] openURL:urlApp]; 
    }else{ 
     UIAlertView *appMissingAlertView = [[UIAlertView alloc] initWithTitle:@"Twitter App Not Installed!" message:@"Please install the Twitter App on your iPhone." delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Ok",nil]; 
     [appMissingAlertView show]; 
     [appMissingAlertView release]; 
    } 
11

다음의 코드는, 이미 설치되어있는 경우 트위터 앱에서 트위터 페이지가 열립니다 달리 트위터를 엽니 다 사파리 :

NSURL *twitterURL = [NSURL URLWithString:@"twitter://user?screen_name=username"]; 
if ([[UIApplication sharedApplication] canOpenURL:twitterURL]) 
    [[UIApplication sharedApplication] openURL:twitterURL]; 
else 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.twitter.com/username"]]; 

은 당신의 이름으로 '이름'을 대체하는 것을 잊지 마십시오.

+0

LSApplicationQueriesSchemes를 info.plist에 추가해야합니다. – appthumb

0

이것은 Swift에서 요구되는 전체 코드입니다. 나는 스위프트 4를 사용하고 있지만, 나는이 답변에 대한 URL에 표시된 세 개의 슬래시가 있습니다 Don't forget to allow access to using the scheme in your info.plist file.

let Username = "YOUR_USERNAME_HERE" 
let appURL = NSURL(string: "twitter:///user?screen_name=\(Username)")! 
let webURL = NSURL(string: "https://twitter.com/\(Username)")! 
let application = UIApplication.shared 
if application.canOpenURL(appURL as URL) { 
     application.open(appURL as URL) 
    } else { 
     // if Instagram app is not installed, open URL inside Safari 
     application.open(webURL as URL) 
    } 
관련 문제