답변:
Kevin이 지적한 것처럼 URL 체계는 앱간에 통신하는 유일한 방법입니다. 따라서, 임의의 앱을 시작할 수 없습니다.
그러나 URL 스키마를 등록하는 앱은 애플이든, 개발자 든, 다른 개발자이든 관계없이 시작할 수 있습니다. 문서는 다음과 같습니다.
전화를 시작하는 tel:경우 전화가 시작되기 전에 링크에 세 자리 이상이 필요한 것 같습니다 . 따라서 전화를 걸지 않고 앱에 들어갈 수 없습니다.
다른 앱을 열 수있는 앱을 작성하기 쉽다는 것을 알았습니다.
FirstApp및 이라는 두 개의 앱이 있다고 가정 해 봅시다 SecondApp. FirstApp을 열 때 버튼을 클릭하여 SecondApp을 열 수 있기를 원합니다. 이를위한 해결책은 다음과 같습니다.
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이 열립니다.
Info.plist하십시오 FirstApp. 그리고이 경우, 개방에 앱이 원하는 것을 스킴을 추가 할 Item 0것iOSDevTips
LSApplicationQueriesSchemesSecondApp을 열려면 FirstApp이 Info.plist 에 추가해야합니다 .
이 답변은 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®istered=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 : //? 유형 만으로도 앱을 열 수 있습니다 . 사파리 브라우저에서
다음 코드를 사용하면 응용 프로그램에서 응용 프로그램을 시작할 수 있습니다
참고 : 환상이라는 이름을 실제 응용 프로그램 이름으로 바꾸십시오.
NSString *mystr=[[NSString alloc] initWithFormat:@"fantacy://location?id=1"];
NSURL *myurl=[[NSURL alloc] initWithString:mystr];
[[UIApplication sharedApplication] openURL:myurl];
URL 체계를 등록한 앱만 시작할 수 있습니다. 그런 다음 sms :를 사용하여 SMS 앱을 여는 것처럼 URL 체계를 사용하여 앱을 열 수 있습니다.
LaunchMe라는 문서에는이 예제를 보여주는 매우 좋은 예가 있습니다.
2017 년 11 월 6 일부터 LaunchMe 샘플 코드 .
나는 또한 얼마 전에 이것을 시도했다 ( Identifier로 iPhone 응용 프로그램 시작 ).이를 수행하는 문서화 된 방법은 확실히 없다. :)
Swift 4.1 및 Xcode 9.4.1에서
1) PageViewControllerExample과 2) DelegateExample의 두 가지 앱이 있습니다. 이제 PageViewControllerExample 앱으로 DelegateExample 앱을 열고 싶습니다. PageViewControllerExample에서 열기 버튼을 클릭하면 DelegateExample 앱이 열립니다.
이를 위해 두 앱 모두에 대해 .plist 파일을 약간 변경해야합니다.
1 단계
DelegateExample 앱에서 .plist 파일을 열고 URL 유형 및 URL 체계를 추가하십시오. 여기에 "myapp"와 같은 필수 이름을 추가해야합니다.
2 단계
PageViewControllerExample 앱에서 .plist 파일을 열고이 코드를 추가하십시오.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>myapp</string>
</array>
이제 PageViewControllerExample에서 버튼을 클릭하면 DelegateExample 앱을 열 수 있습니다.
//In PageViewControllerExample create IBAction
@IBAction func openapp(_ sender: UIButton) {
let customURL = URL(string: "myapp://")
if UIApplication.shared.canOpenURL(customURL!) {
//let systemVersion = UIDevice.current.systemVersion//Get OS version
//if Double(systemVersion)! >= 10.0 {//10 or above versions
//print(systemVersion)
//UIApplication.shared.open(customURL!, options: [:], completionHandler: nil)
//} else {
//UIApplication.shared.openURL(customURL!)
//}
//OR
if #available(iOS 10.0, *) {
UIApplication.shared.open(customURL!, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(customURL!)
}
} else {
//Print alert here
}
}