0

我的应用程序委托中有此代码:

- (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];
                                     }];
 }
4

2 回答 2

0

你没有。当您在应用程序的 plist 中注册 URL 语法时,操作系统会调用它。

然后,您可以使用此方法来处理请求。

即,如果您有一个 wordsearch 应用程序,那么您可能拥有它,以便用户可以从电子邮件中的链接打开 wordsearch,例如...

wordsearch://thisisthecontetnofthewordsearchhfsadkljfhasdkfjahsdkfjhaskljasdhflkjahsgdflkjadhslfkj

然后你会使用这个函数来解析字符串并将它变成一个实际的单词搜索谜题(或类似的东西)。

你真正想从你的 UIViewController 做什么?

于 2012-11-12T15:18:13.403 回答
0

你有两个选择:

  1. 将 in 传递给NSURLonUIViewController实例化或其他方式。

  2. 从您的UIViewController中,获取对应用程序委托的引用并使用该openedURL属性。

选项 2 的代码

MyViewController *controller = [[UIApplication sharedApplication] delegate];
controller.openedURL;
于 2012-11-12T15:18:47.747 回答