다른 곳에서 앱 실행 (iPhone)
다른 응용 프로그램 내에서 임의의 iPhone 응용 프로그램을 시작할 수 있습니까?, 예를 들어 사용자가 버튼을 누르고 전화 응용 프로그램으로 바로 시작하려면 (현재 응용 프로그램을 닫고 전화 응용 프로그램을 열려면) 내 응용 프로그램에서 .
이것이 가능할까요? 전화 URL 링크를 사용하여 전화를 걸 때이 작업을 수행 할 수 있다는 것을 알고 있지만 특정 번호를 누르지 않고 전화 앱을 시작하고 싶습니다.
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이 열립니다.
이 대답은 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 스킴 등록이 포함 된 새 버전을 먼저 업로드해야합니다.
Here is a good tutorial for launching application from within another app:
iOS SDK: Working with URL Schemes
And, it is not possible to launch arbitrary application, but the native applications which registered the URL Schemes.
To achieve this we need to add few line of Code in both App
App A: Which you want to open from another App. (Source)
App B: From App B you want to open App A (Destination)
Code for App A
Add few tags into the Plist of App A Open Plist Source of App A and Past below XML
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.TestApp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>testApp.linking</string>
</array>
</dict>
</array>
In App delegate of App A - Get Callback here
- (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
}
Now coming to App B code -
If you just want to open App A without any input parameter
-(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];
}
}
If you want to pass parameter from App B to App A then use below Code
-(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];
}
}
Note: You can also open App with just type testApp.linking://? on safari browser
Try the following code will help you to Launch an application from your application
Note: Replace the name fantacy with actual application name
NSString *mystr=[[NSString alloc] initWithFormat:@"fantacy://location?id=1"];
NSURL *myurl=[[NSURL alloc] initWithString:mystr];
[[UIApplication sharedApplication] openURL:myurl];
You can only launch apps that have registered a URL scheme. Then just like you open the SMS app by using sms:, you'll be able to open the app using their URL scheme.
There is a very good example available in the docs called LaunchMe which demonstrates this.
LaunchMe sample code as of 6th Nov 2017.
No it's not. Besides the documented URL handlers, there's no way to communicate with/launch another app.
I also tried this a while ago (Launch iPhone Application with Identifier), but there definitely is no DOCUMENTED way to do this. :)
In Swift 4.1 and Xcode 9.4.1
I have two apps 1)PageViewControllerExample and 2)DelegateExample. Now i want to open DelegateExample app with PageViewControllerExample app. When i click open button in PageViewControllerExample, DelegateExample app will be opened.
For this we need to make some changes in .plist files for both the apps.
Step 1
In DelegateExample app open .plist file and add URL Types and URL Schemes. Here we need to add our required name like "myapp".
Step 2
In PageViewControllerExample app open .plist file and add this code
<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
}
}
스위프트 3 빠른 붙여 넣기 버전의 @ villy393에 대한 답변 :
if UIApplication.shared.canOpenURL(openURL) {
UIApplication.shared.openURL(openURL)
} else if UIApplication.shared.canOpenURL(installUrl)
UIApplication.shared.openURL(installUrl)
}
이 주제에 관한 부가 정보 ...
등록되지 않은 프로토콜에 대한 50 개의 요청 제한이 있습니다.
이 토론에서 애플은 특정 버전의 앱에 canOpenUrl
대해 제한된 횟수 만 쿼리 할 수 있으며 선언되지 않은 스키마를 50 번 호출 한 후에는 실패 한다고 언급합니다 . 또한이 실패 상태에 들어간 후 프로토콜이 추가되면 여전히 실패한다는 것을 알았습니다.
이것을 알고 누군가에게 유용 할 수 있습니다.
참고 URL : https://stackoverflow.com/questions/419119/launch-an-app-from-within-another-iphone
'Programming' 카테고리의 다른 글
스위치 문 : 마지막 경우가 기본값이어야합니까? (0) | 2020.05.29 |
---|---|
Java NIO FileChannel 및 FileOutputstream 성능 / 유용성 (0) | 2020.05.29 |
기술적으로 Erlang의 프로세스가 OS 스레드보다 효율적인 이유는 무엇입니까? (0) | 2020.05.29 |
안드로이드 웹뷰 느림 (0) | 2020.05.29 |
HttpClient-작업이 취소 되었습니까? (0) | 2020.05.29 |