[英]NSNotification centre to observe whether an application is opened through URL Scheme
我有一個類,它將使NSNotificationCenter
觀察該應用程序是否處於活動狀態或已進入后台,並將根據該操作進行一系列操作。
我想設置一個NSNotificationCenter
來觀察該應用程序是否通過URL方案打開。
這是我嘗試的:
[[NSNotificationCenter defaultCenter] addObserver:[self class] selector:@selector(appOpenedThroughUrl:) name:UIApplicationLaunchOptionsURLKey object:nil];
但是當應用程序通過URL打開時沒有被調用,請給我一些想法。
我不想使用委托:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
+(void)appOpenedThroughUrl:(NSNotification *)notification {
NSLog(@"%@",notification.userInfo);
}
您需要通過自定義網址方案[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationLaunchOptionsURLKey object:self]打開時發布通知。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.