Για να επιτευχθεί αυτό θα πρέπει να προσθέσετε μερικές γραμμή κώδικα, τόσο App
App A: Ποια θέλετε να ανοίξετε από μια άλλη εφαρμογή.
App Β : Από το App Β θέλετε να ανοίξετε App A
Κώδικας App A
Προσθέστε μερικές ετικέτες στο Plist του App A
Open Plist Πηγή App Α και Παρελθόν παρακάτω XML
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.TestApp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>testApp.linking</string>
</array>
</dict>
</array>
Στο App εκπρόσωπος του App 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
}
Τώρα έρχονται στο App κωδικό B -
Αν απλά θέλετε να ανοίξετε App Α χωρίς καμία παράμετρο εισόδου
-(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 Β σε App Α , στη συνέχεια, χρησιμοποιήστε τον παρακάτω κώδικα
-(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];
}
}
Σημείωση: Μπορείτε επίσης να ανοίξετε App με απλά πληκτρολογήστε testApp.linking: //; στον browser Safari