通过URL协议实现从Safari等浏览器中跳转打开你的app
效果如图,打开safari或其他浏览器输入abcdefg://
然后回车确认跳转到app
下边是具体流程:
1、首先在项目中的plist文件中添加如下内容(红色箭头标明出是随便写的,其中abcdefg为跳转时的URL前缀,com.abc.abc尚未发现有何作用...)
+(void)alert:(NSString*)information{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"程序通过URL协议打开,该URL为:“%@”",information] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alert show];
[alert release];
}
3、在项目入口类AppDelegate.m中有如下回调方法
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
NSString *urlString=[url absoluteString];
[ViewController alert:urlString];//调用视图弹出框
NSLog(@"openURL---->%@",url);
NSLog(@"sourceApplication---->%@",sourceApplication);
NSLog(@"annotation---->%@",annotation);
return YES;
}