我在我的app delegate中有这段代码:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
self.openedURL = url;
// attempt to extract a token from the url
return [FBSession.activeSession handleOpenURL:url];
}
如何从UIViewController调用它?
编辑:
- (IBAction)authButtonAction:(id)sender {
/*
AppDelegate *appDelegate =
[[UIApplication sharedApplication] delegate];*/
// The user has initiated a login, so call the openSession method
// and show the login UX if necessary.
//[appDelegate openSessionWithAllowLoginUI:YES];
// If the user is authenticated, log out when the button is clicked.
// If the user is not authenticated, log in when the button is clicked.
if (FBSession.activeSession.isOpen) {
[FacebookDialogueViewControllerDelegate closeSession];
} else {
// The user has initiated a login, so call the openSession method
// and show the login UX if necessary.
[FacebookDialogueViewControllerDelegate openSessionWithAllowLoginUI:YES];
}
}
...视图控制器然后有这个:
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
return [FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}
答案 0 :(得分:0)
你没有。当您在应用程序的plist中注册URL语法时,操作系统会调用此方法。
然后,您可以使用此方法处理请求。
即。如果您有wordsearch应用程序,那么您可以拥有它,以便用户可以通过电子邮件中的链接打开wordsearch ...
单词搜索:// thisisthecontetnofthewordsearchhfsadkljfhasdkfjahsdkfjhaskljasdhflkjahsgdflkjadhslfkj
然后你会使用这个函数来解析字符串并把它变成一个真正的wordsearch拼图(或类似的东西)。
你真正想从你的UIViewController做什么?
答案 1 :(得分:0)
您有两种选择:
在实例化或其他情况下将NSURL
传递到UIViewController
。
从UIViewController
,获取对应用代表的引用,并使用openedURL
属性。
选项2的代码
MyViewController *controller = [[UIApplication sharedApplication] delegate];
controller.openedURL;