我在我的应用程序中使用 Flickr。当我单击 Flickr 按钮时,它会重定向到 safari 以使用 Flickr 和授权登录。
然后在成功授权后重定向到我的应用程序。但是在重定向之后我想调用 ViewWillAppear。我还设置了 <UIApplicationDelegate>
在我看来。但它没有调用以下任何方法。
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
NSLog(@"@@@@@@@@@@@@@@@@@@@@@Flickr Authorized is completed");
}
- (void)UIApplicationWillEnterForeground:(UIApplication *)application
{
NSLog(@"@@@@@@@@@@@@@@@@@@@@@Flickr Authorized is completed at foreground");
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
NSLog(@"@@@@@@@@@@@@@@@@@@@@@Flickr Authorized is completed at become active");
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSLog(@"@@@@@@@@@@@@@@@@@@@@@@Flickr Authorized is completed at openURL");
}
-(void)viewWillAppear:(BOOL)animated
{
NSLog(@"@@@@@@@@@@@@@@@@@@@@@Flickr Authorized is completed at viewWillAppear");
[super viewWillAppear:YES];
}
但在 AppDelegate 从 safari 重定向后调用 Below 方法。我使用了 SnapAndRun flickr 示例中的代码。
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSLog(@"@@@@@@@@@@@@@@@@@@@@@@Call Back Here@@@@@@@@@@@");
if ([self flickrRequest].sessionInfo)
{
// already running some other request
NSLog(@"Already running some other request");
}
else {
NSString *token = nil;
NSString *verifier = nil;
BOOL result = OFExtractOAuthCallback(url, [NSURL URLWithString:SRCallbackURLBaseString], &token, &verifier);
if (!result) {
NSLog(@"Cannot obtain token/secret from URL: %@", [url absoluteString]);
return NO;
}
[self flickrRequest].sessionInfo = kGetAccessTokenStep;
[flickrRequest fetchOAuthAccessTokenWithRequestToken:token verifier:verifier];
[activityIndicator startAnimating];
//[viewController.view addSubview:progressView];
}
return YES;
}
我知道我们可以在这里调用我的 View Controller 方法。但是在我的 View 本身重定向后,是否有任何替代方法可以调用默认委托(delegate)方法。
任何建议将不胜感激。 提前致谢。
最佳答案
您可以使用通知中心。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someMethod:) name:@"UIApplicationDidBecomeActiveNotification"object:nil];
关于ios - 从 safari 重定向到 IOS 中的 View Controller 后如何调用 viewWillAppear,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22530005/