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;
}
}