45
44

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

iPhone端末内にアプリがある場合はアプリを、ない場合はAppStoreを開くコード

Last updated at Posted at 2014-02-24

iPhoneの端末内にあるアプリをURLスキームによる起動を試みる。
起動が可能ならばそのまま起動する。
起動できなければAppStoreへ遷移させる。
もちろん、対象のアプリにURLスキームが設定されていなくてはいけない。

    // URLスキームでアプリを開けるなら開く
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"~URLスキームの値~"]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"~URLスキームの値~"]];
    }else{
        // URLスキームでアプリを開けないならAppStoreを開く
        NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com/jp/app/id[~アプリのID~]&mt=8"];
        [[UIApplication sharedApplication] openURL:url];
    }
45
44
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
45
44

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?