LoginSignup
3
4

More than 5 years have passed since last update.

URLschemeのiOS9対応で今更ハマる

Last updated at Posted at 2016-07-08

1つめの落とし穴

LSApplicationQueriesSchemesの設定名には「://」はつけない

間違い
hogehoge://

正解
hogehoge

「://」をつけずに「LSApplicationQueriesSchemes」に登録しましょう。

2つ目の落とし穴

UIApplication.sharedApplication().canOpenURLには「://」をつける

間違い

@IBAction func ButtonAction(sender: AnyObject) {
        let url = NSURL(string: "hogehoge")!
        if (UIApplication.sharedApplication().canOpenURL(url)) {        
            //openURLはパラメーターなど含めて別途生成すること
            let prm = String ("hogehoge// ~パラメーターなど~")
            let openUrl = NSURL(string:prm)
           UIApplication.sharedApplication().openURL(openUrl)
        }
    }

正解

@IBAction func ButtonAction(sender: AnyObject) {
        let url = NSURL(string: "hogehoge://")!
        if (UIApplication.sharedApplication().canOpenURL(url)) {             
            let prm = String ("hogehoge// ~パラメーターなど~")
            let openUrl = NSURL(string:prm)
            UIApplication.sharedApplication().openURL(openUrl)
        }
    }

3つ目の落とし穴

LSApplicationQueriesSchemesの設定は、呼び出しアプリ側!
(地味にこれでハマった....

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4