[英]Can I possibly get the parameter in URL Scheme when my app set to not run in background?
I am trying to open my app using URL Scheme with a parameter on it, my problem is, is it possible to get the parameter when the app is set to not run in the background. 我正在尝试使用带有参数的URL方案打开我的应用程序,我的问题是,当应用程序设置为不在后台运行时,是否可以获取参数。
SampleApp-info.plist SampleApp-info.plist
<key>UIApplicationExitsOnSuspend</key>
<true/>
AppDelegate.m AppDelegate.m
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation;
{
NSLog(@"url recieved: %@", url);
NSLog(@"scheme: %@", [url scheme]);
NSLog(@"query string: %@", [url query]);
NSLog(@"host: %@", [url host]);
return YES;
}
When UIApplicationExitsOnSuspend is set to true and try to open my app from Safari, it's not creating any logs but when I remove the key it is working well. 当UIApplicationExitsOnSuspend设置为true并尝试从Safari打开我的应用程序时,它没有创建任何日志,但是当我删除密钥时,它运行良好。 I have to restart my app to load the first viewcontroller and suspending it on the background is the best way, I think...
我认为我必须重新启动应用程序才能加载第一个ViewController,并将其挂起在后台是最好的方法。
Can anyone help me on this? 谁可以帮我这个事? or a better way so I can reload my app starting in the first viewcontroller?
还是更好的方法,以便我可以从第一个ViewController开始重新加载我的应用程序? Newbie here.
新手在这里。
I really appreciate any help. 我非常感谢您的帮助。 Thank you and regards.
谢谢和问候。
UIApplicationExitsOnSuspend Settings UIApplicationExitsOnSuspend设置
You have to set UIApplicationExitsOnSuspend to false . 您必须将UIApplicationExitsOnSuspend设置为false 。 URL Scheme Callback will not work with UIApplicationExitsOnSuspend set to true .
URL方案回调在UIApplicationExitsOnSuspend设置为true时不起作用。 If you want to have a simular behavior like UIApplicationExitsOnSuspend set to true just add the following code
如果要将UIApplicationExitsOnSuspend这样的模拟行为设置为true,只需添加以下代码
- (void)applicationDidEnterBackground:(UIApplication *)application {
[super applicationDidEnterBackground:application];
exit(0);
}
First you have to make an entry in in Info.plist 首先,您必须在Info.plist中进行输入
eg entry your URL Scheme. 例如,输入您的URL方案。 In this case (in the picture) the callback will be blurry:// the identifier should be normally unique
在这种情况下(如图),回调将是模糊的://标识符通常应该是唯一的
Callback Implementation 回调实现
For Pre iOS 9 swift 对于iOS 9之前的版本
optional func application(_ application: UIApplication,
handleOpenURL url: NSURL) -> Bool {
NSLog("URL is %@", url)
return true
}
For Pre iOS 9 objective-c 对于iOS 9之前的Objective-c
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
// handler code here
NSLog(@"Url is %@, url);
return YES;
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
// handler code here
NSLog(@"Url is %@, url);
return YES;
}
IOS 9 objective-c iOS 9 Objective-C
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<NSString *,
id> *)options {
NSLog(@"Url is %@", url);
return YES;
}
IOS 9 - Swift iOS 9-迅捷
optional func application(_ app: UIApplication,
openURL url: NSURL,
options options: [String : AnyObject]) -> Bool {
NSLog("URL is", NSURL)
return true
}
Test the callback 测试回调
Just open the weburl in the example case blurry://test with the mobile safari on your Handy 只需在您的Handy上使用移动Safari的示例案例blurry:// test中打开weburl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.