[ios] 다른 곳에서 앱 실행 (iPhone)

가능?, 다른 응용 프로그램 내에서 임의의 아이폰 응용 프로그램을 실행하는 것입니다 예를 들어 나는 사용자가 (가까운 현재 응용 프로그램 전화 앱을 열고) 전화 응용 프로그램에 버튼을 발사 권리를 밀어하려면 내 응용 프로그램에서 .

이것이 가능할까요? 전화 URL 링크로 전화를 걸 때이 작업을 수행 할 수 있다는 것을 알고 있지만 특정 번호를 누르지 않고 전화 앱을 시작하려고합니다.



답변

Kevin이 지적한 것처럼 URL 체계는 앱간에 통신하는 유일한 방법입니다. 따라서, 임의의 앱을 시작할 수 없습니다.

그러나 URL 스키마를 등록하는 앱은 애플이든, 개발자 든, 다른 개발자이든 관계없이 시작할 수 있습니다. 문서는 다음과 같습니다.

다른 응용 프로그램과 통신

전화를 시작하는 tel:경우 전화가 시작되기 전에 링크에 세 자리 이상이 필요한 것 같습니다 . 따라서 전화를 걸지 않고 앱에 들어갈 수 없습니다.


답변

다른 앱을 열 수있는 앱을 작성하기 쉽다는 것을 알았습니다.

FirstApp및 이라는 두 개의 앱이 있다고 가정 해 봅시다 SecondApp. FirstApp을 열 때 버튼을 클릭하여 SecondApp을 열 수 있기를 원합니다. 이를위한 해결책은 다음과 같습니다.

  1. SecondApp에서

    SecondApp의 plist 파일로 이동 하면 문자열 iOSDevTips 가 포함 된 URL 스킴 을 추가해야합니다 (물론 다른 문자열을 작성할 수 있음).

여기에 이미지 설명을 입력하십시오

2. FirstApp에서

아래 작업으로 버튼을 만듭니다.

- (void)buttonPressed:(UIButton *)button
{
  NSString *customURL = @"iOSDevTips://";

  if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:customURL]])
  {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
  }
  else
  {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"URL error"
                              message:[NSString stringWithFormat:@"No custom URL defined for %@", customURL]
                              delegate:self cancelButtonTitle:@"Ok"
                              otherButtonTitles:nil];
    [alert show];
  }

}

그게 다야. 이제 FirstApp에서 버튼을 클릭하면 SecondApp이 열립니다.


답변

이 답변은 8 이전의 iOS에서는 절대적으로 정확합니다.

iOS 9 이상에서는 앱이 Info.plist에서 LSApplicationQueriesSchemes 키 (문자열 배열) 아래에 쿼리하려는 URL 스킴을 화이트리스트에 추가해야합니다.

여기에 이미지 설명을 입력하십시오


답변

스위프트에서

누군가가 빠른 Swift 복사 및 붙여 넣기를 찾고있는 경우를 대비하여.

if let url = NSURL(string: "app://") where UIApplication.sharedApplication().canOpenURL(url) {
            UIApplication.sharedApplication().openURL(url)
} else if let itunesUrl = NSURL(string: "https://itunes.apple.com/itunes-link-to-app") where UIApplication.sharedApplication().canOpenURL(itunesUrl) {
            UIApplication.sharedApplication().openURL(itunesUrl)
}


답변

다른 응용 프로그램에서 응용 프로그램을 열려면 두 응용 프로그램을 모두 변경해야합니다. iOS 10 업데이트에서 Swift 3 을 사용하는 단계는 다음과 같습니다 .

1. 열려고하는 응용 프로그램을 등록하십시오

Info.plist응용 프로그램의 고유하고 고유 한 URL 체계를 정의하여를 업데이트하십시오 .

여기에 이미지 설명을 입력하십시오

구성표 이름은 고유해야합니다. 그렇지 않으면 장치에 동일한 URL 구성표 이름을 가진 다른 응용 프로그램이 설치되어 있으면 어느 응용 프로그램이 실행되는지 런타임으로 결정됩니다.

2. 기본 응용 프로그램에 이전 URL 체계를 포함

canOpenURL:UIApplication클래스 의 메소드 와 함께 사용할 수 있도록 URL 스킴을 지정해야합니다 . 메인 애플리케이션을 열고 Info.plist다른 애플리케이션의 URL 스킴을에 추가하십시오 LSApplicationQueriesSchemes. (iOS 9.0에서 도입)

여기에 이미지 설명을 입력하십시오

3. 응용 프로그램을 여는 동작을 구현하십시오.

이제 모든 것이 설정되었으므로 다른 응용 프로그램을 여는 기본 응용 프로그램에서 코드를 작성하는 것이 좋습니다. 이것은 다음과 같아야합니다.

let appURLScheme = "MyAppToOpen://"

guard let appURL = URL(string: appURLScheme) else {
    return
}

if UIApplication.shared.canOpenURL(appURL) {

    if #available(iOS 10.0, *) {
        UIApplication.shared.open(appURL)
    }
    else {
        UIApplication.shared.openURL(appURL)
    }
}
else {
    // Here you can handle the case when your other application cannot be opened for any reason.
}

AppStore에서 설치 한 기존 앱을 열려면 이러한 변경 사항에 새로운 릴리스가 필요합니다. 이미 Apple AppStore에 출시 한 응용 프로그램을 열려면 URL 스킴 등록이 포함 된 새 버전을 먼저 업로드해야합니다.


답변

다음은 다른 앱 내에서 응용 프로그램을 시작하는 데 유용한 자습서입니다.
iOS SDK : URL Schemes 작업
임의의 응용 프로그램을 시작할 수 없지만 URL Schemes 를 등록한 기본 응용 프로그램은 실행할 수 없습니다 .


답변

이를 달성하기 위해 우리는 두 앱 모두에 몇 줄의 코드를 추가해야

앱 A : 다른 앱에서 열려고합니다. (출처)

앱 B : 열려는 앱 B에서 인앱을 (대상)

앱 A 용 코드

의 PLIST에 몇 가지 태그를 추가 인앱
XML 아래 열기 PLIST 앱 (A)의 소스 및 과거

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>com.TestApp</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>testApp.linking</string>
        </array>
    </dict>
</array>

앱 A 의 앱 델리게이트 -콜백 받기

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
// You we get the call back here when App B will try to Open 
// sourceApplication will have the bundle ID of the App B
// [url query] will provide you the whole URL 
// [url query] with the help of this you can also pass the value from App B and get that value here 
}

이제 오는 앱 B 코드

입력 매개 변수없이 App A를 열려면

-(IBAction)openApp_A:(id)sender{

    if(![[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"testApp.linking://?"]]){
         UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"App is not available!" message:nil delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
            [alert show];

        }
}

App B 에서 App A 로 매개 변수를 전달 하려면 아래 코드를 사용하십시오.

-(IBAction)openApp_A:(id)sender{
    if(![[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"testApp.linking://?userName=abe&registered=1&Password=123abc"]]){
         UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"App is not available!" message:nil delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
            [alert show];

        }
}

참고 : testApp.linking : //? 유형 만으로도 앱을 열 수 있습니다 . 사파리 브라우저에서