티스토리 뷰

iOS/자료정리

[iOS]앱에서 다른앱 실행하기.

썩소천사 2011. 10. 27. 14:30
반응형

//어플에서 설치되어 있는 다른 어플을 실행할 수 있으며 인자값을 넘길 수 있다.

//???_info.plist 에 URL types 을 추가하고 그 안에 
URL Schemes : "test"
URL identifier  : "com.youCompany.test"
를 정의해 준다. xcode4 에서는 plist에 URL types를 추가할 경우 해당 어플 Project ->Target -> "Info"탭 하단에 URL types를 추가하는 곳이 별도로 존재 한다.


//실행될 어플 delegate에 추가.
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url 
{
    NSLog(@"handleOpenURL");
    
    NSString *URLString = [url absoluteString];
    NSString *message = [NSString stringWithFormat:@"URL: %@", URLString];
    
    UIAlertView *openURLAlert = [[UIAlertView alloc] initWithTitle:@"handleOpenURL:"
                                                           message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    
    [openURLAlert show];
    [openURLAlert release];
    
    return YES;
}

//해당 어플을 호출할때에는
NSString *appUrl = @"test://(다른 내용을 뒤에 덧붙여 보낼 수 있음)";  //url scheme 값을 주소형식으로 입력
NSString *appStoreUrl = @"XXXXX";  // 앱스토어에 올라가 있는 앱 링크 주소"
BOOL isInstall = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:appUrl]];

// 설치되어 있지 않았다면 해당 앱스토어로 이동
if (!isInstall) {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:appStoreUrl]];
}


이 밖에도 tel, sms, email등등을 호출할 수 있다. 참고한 사이트 및 자세한 내용은 하단의 링크로..

http://iphonedevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html

http://wiki.akosma.com/IPhone_URL_Schemes

http://cafe.naver.com/mcbugi/92658



반응형
댓글
반응형