iOS URL方案-在我的应用程序中加载自定义UIView
我引用了此 IOS URL方案在我的应用程序中启动了自定义UIView ,但我不清楚他在做什么答案.
I referred this IOS url Scheme launch custom UIView inside my application, but i am not clear what he s trying to answer.
是否可以通过URL方案在我的应用登录屏幕上加载自定义UIVIew?
Is it possible to load custom UIVIew over my app login screen through URL Scheme ?
我的场景-我将自定义视图显示为登录视图过程中的弹出窗口,它在其中检查应用程序是否已接受条款和条件.当应用程序在后台运行以及从已安装的应用程序启动应用程序时,它可以很好地工作.
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.
但是,当我从"URL方案"部分启动应用程序时,当应用程序在后台运行时,它可以正常工作,但是当应用程序终止时,我从URL方案中打开应用程序,则启动了应用程序,但是自定义视图立即被隐藏.
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.
- (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;
}
您需要在委托方法中加载所有资源和rootViewController
You need load all resources and rootViewController in delegate method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions
,并且在此方法中(如果您通过url打开应用),launchOptions具有键UIApplicationLaunchOptionsURLKey.通过此键获取对象并像在
and in this method if you opened app by url, launchOptions has a key 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
类似这样的东西
- (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;
}
别忘了从rootViewController展示您的自定义视图控制器
And don't forget present your custom view controller from rootViewController