openURL能帮助你运行Maps,SMS,Browser,Phone甚至其他的应用程序。

openURL的使用方法: 

[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:myURLString]];

自己定义URL,方法如下: 

打开info.plist,添加一项URL types

展开URL types,再展开Item1,将Item1下的URL identifier修改为URL Scheme
展开URL Scheme,将Item1的内容修改为myapp

或者:

(增加一下此段设置)
<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>myapp</string>
            </array>
            <key>CFBundleURLName</key>
            <string>com.yourcompany.appName</string>
        </dict>
    </array>

其他程序可通过myapp://访问此自定义URL

可通过[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"myapp://com.yourcompany.appName"]];

来判断用户机器中是否安装了该程序

最近接触到程序内打开自己,通过第三方控件来调用本身程序:

通过- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

可以通过处理url来获取信息扫行相应操作。

 

 

01 -(IBAction)openMaps {//打开地图
02    // Where is Apple on the map anyway?
03    NSString* addressText = @”1 Infinite Loop, Cupertino, CA 95014″;
04    // URL encode the spaces
05    addressText =  [addressText stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
06    NSString* urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", addressText];
07    // lets throw this text on the log so we can view the url in the event we have an issue
08    NSLog(urlText);
09    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];
10    }
11    -(IBAction)openEmail {//打开mail
12    // Fire off an email to apple support
13    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://devprograms@apple.com"]];
14    }
15    -(IBAction)openPhone {//拨打电话
16    // Call Google 411
17    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8004664411"]];
18    }
19    -(IBAction)openSms {//打开短信
20    // Text to Google SMS
21    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://466453"]];
22    }
23    -(IBAction)openBrowser {//打开浏览器
24    // Lanuch any iPhone developers fav site
25    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunesconnect.apple.com"]];
26    }
 posted on 2011-05-04 14:00  Sure-G  阅读(3203)  评论(0编辑  收藏  举报