如何在 UIWebView 中显示来自 WebApp 的 google 地图方向?
How to show google maps directions from WebApp inside a UIWebView?
我正在努力从我的 WebApp 构建一个 IPA,在 运行 我的 WebApp 在 UIWebView 中我的页面显示 google 带有路由器的地图之后不再工作。
项目是使用swift和IOS7.1构建的,有具体的制作方法吗?
我的代码:
import UIKit
class ViewController: UIViewController , UIWebViewDelegate{
@IBOutlet weak var mWebView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
mWebView.delegate = self
if Reachability.isConnectedToNetwork() {
let url = NSURL(string:"http://my_webapp_.test.com")
let request = NSURLRequest(URL:url!)
mWebView.loadRequest(request)
} else {
var alert = UIAlertController(title: "Alert", message: "you need internet connection to display the content", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func webView(webView: UIWebView, didFailLoadWithError error: NSError) {
}
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
println(request.URL!.absoluteString)
if navigationType == UIWebViewNavigationType.LinkClicked {
if let phoneURL = request.URL where (phoneURL.absoluteString!.rangeOfString("tel://") != nil) {
if UIApplication.sharedApplication().canOpenURL(phoneURL) {
UIApplication.sharedApplication().openURL(phoneURL)
return false
}
}
}
return true
}
}
有什么建议吗?提前致谢!
只需要添加这些信息就成功了!
NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription in my info.plist
我正在努力从我的 WebApp 构建一个 IPA,在 运行 我的 WebApp 在 UIWebView 中我的页面显示 google 带有路由器的地图之后不再工作。
项目是使用swift和IOS7.1构建的,有具体的制作方法吗?
我的代码:
import UIKit
class ViewController: UIViewController , UIWebViewDelegate{
@IBOutlet weak var mWebView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
mWebView.delegate = self
if Reachability.isConnectedToNetwork() {
let url = NSURL(string:"http://my_webapp_.test.com")
let request = NSURLRequest(URL:url!)
mWebView.loadRequest(request)
} else {
var alert = UIAlertController(title: "Alert", message: "you need internet connection to display the content", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func webView(webView: UIWebView, didFailLoadWithError error: NSError) {
}
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
println(request.URL!.absoluteString)
if navigationType == UIWebViewNavigationType.LinkClicked {
if let phoneURL = request.URL where (phoneURL.absoluteString!.rangeOfString("tel://") != nil) {
if UIApplication.sharedApplication().canOpenURL(phoneURL) {
UIApplication.sharedApplication().openURL(phoneURL)
return false
}
}
}
return true
}
}
有什么建议吗?提前致谢!
只需要添加这些信息就成功了!
NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription in my info.plist