iPhone调用web的方法

1、 调用iPhone应用程序

调用 自带mail

  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://[email protected]"]];

  调用 电话phone

  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8008808888"]];

  调用 SMS

  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];

  调用自带 浏览器 safari

  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.hzlzh.com"]];

  上面是最基本的语句,没什么处理过程。

  如:调用phone可以传递号码,调用SMS 只能设定号码,不能初始化SMS内容。

  ps:根据Apple的协议,使用 调用浏览器以外的任何调用,都不符合用户条例,因此,较难通过 App Store,慎用。

2、UIViewController 的使用

自建一个WebViewController继承于UIViewController<UIWebViewDelegate>,作为需要弹出的一个页面。代码如下:

h文件:

#import <UIKit/UIKit.h>


@interface WebViewController : UIViewController <UIWebViewDelegate>{

    UIWebView *myWebView;

    NSString* url;

}


@property(nonatomic, retain) IBOutlet UIWebView *myWebView;

@property(nonatomic, retain) NSString* url;


@end

m文件其中比较重要的代码句, 实际就是UIWebViewDelegate中需要重写的方法:

- (void)webViewDidStartLoad:(UIWebView *)webView{

//start load

}


- (void)webViewDidFinishLoad:(UIWebView *)webView{

   //load finished

}


- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{

   //load fail

[self.myWebView loadHTMLString:[NSString stringWithFormat:@"<html><body>%@</body></html>",[error description]] baseURL:nil];

}


参考资料:

http://www.cnmsdn.com/html/201003/1268756224ID2080.html


猜你喜欢

转载自blog.csdn.net/rsp19801226/article/details/7305042
今日推荐