Open maps with specific address iOS 7

后端 未结 5 1103
半阙折子戏
半阙折子戏 2021-02-19 04:14

I am trying to make my application open the apple maps application and have the address be pulled up. I tried this :

- (IBAction)openInMaps:(id)sender {
    NSS         


        
5条回答
  •  误落风尘
    2021-02-19 04:51

    Swift 2 version that is formatted nicely, safely handles optionals, and won't crash your app:

    let baseUrl: String = "http://maps.apple.com/?q="
    let encodedName = "address".stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet()) ?? ""
    let finalUrl = baseUrl + encodedName
    if let url = NSURL(string: finalUrl) {
        UIApplication.sharedApplication().openURL(url)
    }
    

提交回复
热议问题