openURL的使用

openURL的使用方法:
       [[UIApplication sharedApplication] openURL:[NSURL URLWithString:appString]];  
其中系统的appString有:
1.Map    http://maps.google.com/maps?q=Shanghai  
2.Email  mailto://[email protected]  
3.Tel    tel://10086  
4.Msg    sms://10086  

除此之外,还可以自己定义URL,方法如下:

  1. 打开info.plist,添加一项URL types
  2. 展开URL types,再展开Item1,将Item1下的URL identifier修改为URL Scheme
  3. 展开URL Scheme,将Item1的内容修改为myapp
  4. 其他程序可通过myapp://访问此自定义URL


openURL能帮助你运行Maps,SMS,Browser,Phone甚至其他的应用程序。这是Iphone开发中我经常需要用到的一段代码,但是其调用只是内部调用。

- (IBAction)openMaps {
    //打开地图 
   NSString*addressText = @"beijing";
    //@"1Infinite Loop, Cupertino, CA 95014"; 
   addressText =[addressTextstringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; 
   NSString*urlText = [NSStringstringWithFormat:@"http://maps.google.com/maps?q=%@",addressText]; 
   NSLog(@"urlText=============== %@", urlText);
   [[UIApplicationsharedApplication] openURL:[NSURL URLWithString:urlText]];
}

- (IBAction)openEmail {
     //打开mail // Fire off an email to apple support
      [[UIApplication sharedApplication]openURL:[NSURL   URLWithString:@"mailto://[email protected]"]];
 } 
 
- (IBAction)openPhone {
  
    //拨打电话
    // CallGoogle 411
    [[UIApplication sharedApplication] openURL:[NSURLURLWithString:@"tel://8004664411"]];
 } 
 
- (IBAction)openSms {
    //打开短信
     // Text toGoogle SMS
    [[UIApplication sharedApplication] openURL:[NSURLURLWithString:@"sms://466453"]];
}

-(IBAction)openBrowser {
    //打开浏览器
    // Lanuch any iPhone developers fav site
     [[UIApplication sharedApplication] openURL:[NSURLURLWithString:@"http://itunesconnect.apple.com"]];
 }
iphone程序内调用谷歌地图

使用CLLocationManager类,MKMapView。并且实现<MKMapViewDelegate,CLLocationManagerDelegate>
//初始化CLLocationManager,CLLocationManager获得当前地理坐标
locmanager=[[CLLocationManager alloc]init];

[locmanager setDelegate:self];
 //设置精确度
[locmanager setDesiredAccuracy:kCLLocationAccuracyBest];

[locmanagerstartUpdatingLocation];

 

猜你喜欢

转载自dxldy.iteye.com/blog/1753976