6
5

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.

【備忘録】AppController.mm の openURL が呼ばれない!!!

Posted at

openURLが呼ばれる条件

  • didFinishLaunchingWithOptionsの返りがYES
  • アプリ起動中にURLスキームによる起動を行った時

今回やりたかったこと

  • URLスキームのQueryを取得してAPIの引数にしたい

やった事

AppController.mm

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
//
          なんかテキトウな処理があるはず
//

    if ((launchOptions != nil) && ([launchOptions valueForKey:UIApplicationLaunchOptionsURLKey] != nil)) {
        // launchOptionsからNSURLの取得
        NSURL *clickedURL = (NSURL *)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];

        // NSURLがとれるのでopenURLでやりたかった事をこの辺でやる。今回はNSURLからqueryを取得してuserdefaultsに保存
        NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
        [ud setObject:[clickedURL query] forKey:@"Query"];
        [ud synchronize];

        return YES;
    } else {
        return NO;
    }
}
6
5
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
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?