1
votes

I referred this IOS url Scheme launch custom UIView inside my application, but i am not clear what he s trying to answer.

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.

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

1 Answers

2
votes

You need load all resources and rootViewController in delegate method

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions 

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

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