从浏览器将用户重定向到我的应用

时间:2014-01-09 07:53:10

标签: ios iphone ios7 openurl

在我的应用中,我在应用启动时加载了tabbar控制器。在那我正在呈现登录页面,当用户登录时,我正在解雇该登录页面。因此,当应用程序启动时,将有登录页面。现在在登录页面我有一个按钮。 Thar按钮在登录页面上显示注册页面。每当用户完成注册。过程我只是解雇reeg。登录页面的页面。现在在我的应用程序中我正在向用户发送一封邮件,其中包含将用户重定向到我的app reg的链接。页。所以当用户重定向时我想直接向他展示reg。登录页面上的页面。为此,我编写了代码,但它只显示登录页面,当我记录一些reg值时。页面它也打印该值但仅显示登录页面。如果我首先关闭登录页面然后出现reg。在tabbar上的页面然后它工作正常,但正如我之前所说,我希望在reg之后将用户重定向到登录页面。页。我的代码是。::

 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
NSString *urlString=[url absoluteString];
NSLog(@"string%@",urlString);
NSRange r = [urlString rangeOfString:@"myApp" options:NSCaseInsensitiveSearch];

if(r.location != NSNotFound){
    NSLog(@"founddddd");
    NSLog(@"MyApp url %@",url);
    //NSString *str=[url valueForKey:@"email"];
    NSArray *query = [[url query] componentsSeparatedByString:@"&"];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithCapacity:[query count]];
    for(NSString *parameter in query)
    {
        NSArray *kv = [parameter componentsSeparatedByString:@"="];
        [parameters setObject:[kv count] > 1 ? [[kv objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding] : [NSNull null]
                       forKey:[[kv objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding]];
    }

    NSLog(@"Parameters: %@", parameters);



    RegistrationViewController *RegistrationVC=[[RegistrationViewController alloc] initWithNibName:@"RegistrationViewController" bundle:[NSBundle mainBundle]];

    NSLog(@"q = %@", [parameters objectForKey:@"email"]);

      RegistrationVC.fromBrowser=TRUE;
   [loginVC presentViewController:RegistrationVC animated:NO completion:^{
         NSLog(@"txtemail %@ value%@",RegistrationVC.txtEmail,RegistrationVC.txtEmail.text);
       RegistrationVC.txtEmail.userInteractionEnabled=NO;
       RegistrationVC.txtEmail.text=[parameters objectForKey:@"email"];
       RegistrationVC.btnServiceProvider.hidden=YES;
       RegistrationVC.lbl_create.hidden=YES;

    }];


    return YES;

}
  return NO;
  }

这里loginVC我在我的tabbar上显示登录页面时分配。我在我的日志中得到这个::

Warning: Attempt to present <RegistrationViewController: 0xd8699c0> on <LoginViewController: 0xdd51a00> whose view is not in the window hierarchy!

1 个答案:

答案 0 :(得分:0)

用此

代替代码
    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
NSString *urlString=[url absoluteString];
NSLog(@"string%@",urlString);
NSRange r = [urlString rangeOfString:@"myApp" options:NSCaseInsensitiveSearch];

if(r.location != NSNotFound){
    NSLog(@"founddddd");
    NSLog(@"MyApp url %@",url);
    //NSString *str=[url valueForKey:@"email"];
    NSArray *query = [[url query] componentsSeparatedByString:@"&"];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithCapacity:[query count]];
    for(NSString *parameter in query)
    {
        NSArray *kv = [parameter componentsSeparatedByString:@"="];
        [parameters setObject:[kv count] > 1 ? [[kv objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding] : [NSNull null]
                       forKey:[[kv objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding]];
    }

    NSLog(@"Parameters: %@", parameters);



   [self performSelector:@selector(gooRegestraction) withObject:nil afterDelay:0.3];

    return YES;

}
  return NO;
  }

-(void)gooRegestraction{

 RegistrationViewController *RegistrationVC=[[RegistrationViewController alloc] initWithNibName:@"RegistrationViewController" bundle:[NSBundle mainBundle]];

    NSLog(@"q = %@", [parameters objectForKey:@"email"]);

      RegistrationVC.fromBrowser=TRUE;
   [[[UIApplication sharedApplication]keyWindow].rootViewController presentViewController:RegistrationVC animated:YES completion:^{
    RegistrationVC.txtEmail.userInteractionEnabled=NO;
    RegistrationVC.txtEmail.text=[parameters objectForKey:@"email"];
    RegistrationVC.btnServiceProvider.hidden=YES;
    RegistrationVC.lbl_create.hidden=YES;

}];

}