2017-03-04 40 views
0

didFinishLaunchingWithOptions這裏我只是檢查我userNamepassword導航從LogInVC用戶HomeVC如何做認證checkng在「didFinishLaunchingWithOptions'使用URL舍姆參數

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

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    if([defaults objectForKey:@"username"]!=nil && ![[defaults objectForKey:@"password"] isEqualToString:@""]) { 
     [self navigateToMaskViewController]; 

    } else { 
     [self navigateToRSSignInViewController]; 

    } 

    return YES; 
} 

openURL: sourceApplication:在這裏我得到我的登錄憑據(用戶名密碼&),我想在didFinishLaunchingWithOptions用於authetication檢查。

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url 
    sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { 

    BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application 
                    openURL:url 
                 sourceApplication:sourceApplication 
                   annotation:annotation 
        ]; 

    NSLog(@"Calling Application Bundle ID: %@", sourceApplication); 
    NSLog(@"URL scheme:%@", [url scheme]); 
    NSLog(@"URL query: %@", [url query]); 

    if ([url query]) { 
     NSMutableDictionary *queryDict = [[NSMutableDictionary alloc] init]; 
     queryDict = [self getValue:[url query]]; 
     NSString *userName = queryDict[@"userName"]; 
     NSString *password = queryDict[@"password"]; 

     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
     [defaults setObject:userName forKey:@"username"]; 
     [defaults setObject:password forKey:@"password"]; 
     [defaults synchronize]; 

     return YES; 

    } else { 

    } 

    return handled; 
} 

- (NSMutableDictionary *)getValue:(NSString *)query 
{ 
    NSMutableDictionary *queryStringDictionary = [[NSMutableDictionary alloc] init]; 
    NSArray *urlComponents = [query componentsSeparatedByString:@"&"]; 

    for (NSString *keyValuePair in urlComponents) 
    { 
     NSArray *pairComponents = [keyValuePair componentsSeparatedByString:@"="]; 
     NSString *key = [[pairComponents firstObject] stringByRemovingPercentEncoding]; 
     NSString *value = [[pairComponents lastObject] stringByRemovingPercentEncoding]; 

     [queryStringDictionary setObject:value forKey:key]; 
    } 

    return queryStringDictionary; 
} 

但是對於URL計劃didFinishLaunchingWithOptions沒有在openURL: sourceApplication:之後調用。那麼我怎樣才能在didFinishLaunchingWithOptions中進行身份驗證?如果有人瞭解它,請與我分享解決方案。非常感謝提前。當您根據應用程序的生命週期的應用挖掘

回答

0

didFinishLaunchingWithOptions被調用,然後其他代表方法或函數被相應地調用

但首先didFinishLaunchingWithOptions被調用,然後把它移到您的根視圖控制器。

對於驗證檢查,請將您的值保存在[NSUserDefaults standardUserDefaults]中,然後一旦保存,您可以在didFinishLaunchingWithOptions中檢查您的驗證。