2017-11-16 8 views
0

GoogleMap & Wazeのネイティブアプリで両方のモードを運転するモードを開きたいとします。どうやってするの?現在ネイティブGoogleMaps App&Waze Appを開く方法

func showActionSheet(vc: UIViewController) { 
    let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) 

    actionSheet.addAction(UIAlertAction(title: "Google Maps", style: .default, handler: { (alert:UIAlertAction!) -> Void in 
     self.openGoogleMaps() 
    })) 

    actionSheet.addAction(UIAlertAction(title: "Waze", style: .default, handler: { (alert:UIAlertAction!) -> Void in 
     self.openWaze() 
    })) 

    actionSheet.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) 

    vc.present(actionSheet, animated: true, completion: nil) 
} 

私は2つの機能を実装しましたが、私は

func openGoogleMaps() { 
//Don't want open in URL, want to open in native googlemaps app 
     } 

    func openWaze() { 
    //Don't want open in URL, want to open in native Waze app 
} 

答えて

0

最初のチェックのWazeやGoogleマップのアプリが利用可能かどうかについて、ユーザーの両方ともマップのためのネイティブアプリケーションで開く方法を知りたいのですが電話。 その後、URL ScheemeであなたのアプリからWaze/Googleアプリを開くことができます。

func openGoogleMaps() { 
    if (UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!)) { //First check Google Mpas installed on User's phone or not. 
      UIApplication.shared.openURL(URL(string: "comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic")!) //It will open native google maps app. 
    } else { 
      print("Can't use comgooglemaps://"); 
    } 
} 


func openWaze() { 
    if (UIApplication.shared.canOpenURL(URL(string:"waze://")!)) { //First check Waze Mpas installed on User's phone or not. 
     UIApplication.shared.openURL(URL(string: "waze://")!) //It will open native wazw maps app. 
    } else { 
      print("Can't use waze://"); 
    } 
} 

のiOS SDK 9.0でコンパイルすると、後で、あなたがWazeをを含めるように、次を使用して、アプリケーションのプロパティリストファイルを更新する必要があります。

<key>LSApplicationQueriesSchemes</key> 
<array> 
    <string>waze</string> 
</array> 
関連する問題