在didFinishLaunchingWithOptions
這裏我只是檢查我userName
和password
導航從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
中進行身份驗證?如果有人瞭解它,請與我分享解決方案。非常感謝提前。當您根據應用程序的生命週期的應用挖掘