0
我正在從我的WebApp構建一個IPA,在UIWebView中運行我的WebApp後,我的頁面顯示了帶有路由器的Google地圖不起作用。如何在UIWebView中顯示來自WebApp的Google Maps路線?
該項目是用swift和IOS 7.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
}
}
有什麼建議?提前致謝!
您的webapp在瀏覽器上工作,但不在webview中?嗯..不知道,但聽起來像一個「公共API訪問」問題給我... – kaho
你是對的,我沒有把「NSLocationWhenInUseUsageDescription NSLocationAlwaysUsageDescription」在我的info.plist –