Launch an app from within another (iPhone)

后端 未结 14 1666
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 01:14

Is it possible to launch any arbitrary iPhone application from within another app?, For example in my application if I want the user to push a button an

14条回答
  •  忘了有多久
    2020-11-22 01:40

    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

    CFBundleURLTypes
    
        
            CFBundleURLName
            com.TestApp
            CFBundleURLSchemes
            
                testApp.linking
            
        
    
    

    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

提交回复
热议问题