【URL Schemes】The Complete Tutorial on iOS/iPhone Custom URL Schemes

来源:互联网 发布:淘宝涛哥电玩店 编辑:程序博客网 时间:2024/04/28 15:57

地址:http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html


Steps:

  •  Registering a Custom URL Scheme in info.plist for your app (Recommend via XCode)
  • Request from another app:

- (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];  }    }


  • Handler of your app:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url        sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{  // Check the calling application Bundle ID  if ([sourceApplication isEqualToString:@"com.3Sixty.CallCustomURL"])  {    NSLog(@"Calling Application Bundle ID: %@", sourceApplication);    NSLog(@"URL scheme:%@", [url scheme]);    NSLog(@"URL query: %@", [url query]);     return YES;  }  else    return NO;}


 

0 0
原创粉丝点击