[英]iOS URL Scheme - load custom UIView inside my application
I referred this IOS url Scheme launch custom UIView inside my application , but i am not clear what he s trying to answer. 我在我的应用程序中引用了这个IOS url Scheme启动自定义UIView ,但是我不清楚他正在尝试回答什么。
Is it possible to load custom UIVIew over my app login screen through URL Scheme ? 是否可以通过URL Scheme在我的应用程序登录屏幕上加载自定义UIVIew?
My Scenario- I am showing custom view as a pop up in login view process, where it checks, whether app has accepted terms and conditions or not. 我的场景-我将自定义视图显示为登录视图过程中的弹出窗口,它在其中检查应用程序是否已接受条款和条件。 It works fine in when app s running in background as well app as app is launched from installed app.
当应用程序在后台运行以及从已安装的应用程序启动应用程序时,它可以正常工作。
But when i launch app from URL Scheme section, it works fine when app s running in background, but when app get terminated, I open app from URL Schemes, App is launched but custom view gets hide immediately. 但是,当我从“ URL方案”部分启动应用程序时,当应用程序在后台运行时运行良好,但是当应用程序终止时,我从URL方案中打开了应用程序,启动了App,但是自定义视图立即被隐藏。
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
self.isCalledFromSafariBrowser = true;
AppCodeViewController_iPad *appCodeViewController = [[AppCodeViewController_iPad alloc]init];
if (!url)
{
return NO;
}
NSString *URLString = [url absoluteString];
NSArray *arr = [URLString componentsSeparatedByString:@"?"];
arr = [[arr objectAtIndex:1] componentsSeparatedByString:@"&"];
NSArray *usernameArray = [[arr objectAtIndex:0] componentsSeparatedByString:@"="];
NSLog(@"user name = %@",[usernameArray objectAtIndex:1]);
NSArray *passwordArray =[[arr objectAtIndex:1] componentsSeparatedByString:@"="];
NSLog(@"password name = %@",[passwordArray objectAtIndex:1]);
NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults];
NSString * appcode = [standardUserDefaults stringForKey:@"Appcode"];
NSLog(@"app code vlaue == %@",appcode);
if (appcode == (id)[NSNull null] || appcode.length == 0 )
{
[appCodeViewController userLogin:[usernameArray objectAtIndex:1] andPassword:[passwordArray objectAtIndex:1]];
}
else
{
self.username =[usernameArray objectAtIndex:1];
self.SubscriberPwd = [passwordArray objectAtIndex:1];
[self chkPermissions];
}
return YES;
}
You need load all resources and rootViewController in delegate method 您需要在委托方法中加载所有资源和rootViewController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions
and in this method if you opened app by url, launchOptions has a key UIApplicationLaunchOptionsURLKey. 在此方法中,如果您通过url打开应用,则launchOptions具有键UIApplicationLaunchOptionsURLKey。 Get objects by this key and handle it like in your
通过此键获取对象并像在
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
Something like this 像这样
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
application.delegate.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
application.delegate.window.rootViewController = [[YourViewController alloc] init];
[application.delegate.window makeKeyAndVisible];
NSURL *url = launchOptions[UIApplicationLaunchOptionsURLKey];
if (url) {
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
self.isCalledFromSafariBrowser = true;
AppCodeViewController_iPad *appCodeViewController = [[AppCodeViewController_iPad alloc]init];
NSString *URLString = [url absoluteString];
NSArray *arr = [URLString componentsSeparatedByString:@"?"];
arr = [[arr objectAtIndex:1] componentsSeparatedByString:@"&"];
NSArray *usernameArray = [[arr objectAtIndex:0] componentsSeparatedByString:@"="];
NSLog(@"user name = %@",[usernameArray objectAtIndex:1]);
NSArray *passwordArray =[[arr objectAtIndex:1] componentsSeparatedByString:@"="];
NSLog(@"password name = %@",[passwordArray objectAtIndex:1]);
NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults];
NSString * appcode = [standardUserDefaults stringForKey:@"Appcode"];
NSLog(@"app code vlaue == %@",appcode);
if (appcode == (id)[NSNull null] || appcode.length == 0 )
{
[appCodeViewController userLogin:[usernameArray objectAtIndex:1] andPassword:[passwordArray objectAtIndex:1]];
}
else
{
self.username =[usernameArray objectAtIndex:1];
self.SubscriberPwd = [passwordArray objectAtIndex:1];
[self chkPermissions];
}
}
return YES;
}
And don't forget present your custom view controller from rootViewController 并且不要忘记从rootViewController呈现您的自定义视图控制器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.