在Swift中用TWTRShareEmailViewController(Fabric Twitter SDK)请求用户Twitter邮件
我想请求用户的Twitter邮件。 在https://dev.twitter.com/twitter-kit/ios/request-email上,我们可以在Obj-C中看到代码,但是在Swift中需要它,而我无法翻译它。 有谁知道如何,请?
这是Obj-C代码:
if ([[Twitter sharedInstance] session]) { TWTRShareEmailViewController* shareEmailViewController = [[TWTRShareEmailViewController alloc] initWithCompletion:^(NSString* email, NSError* error) { NSLog(@"Email %@, Error: %@", email, error); }]; [self presentViewController:shareEmailViewController animated:YES completion:nil]; } else { // TODO: Handle user not signed in (eg // attempt to log in or show an alert) }
谢谢您的帮助。
这应该粗略地将上面的Objective-C转换成Swift:
if (Twitter.sharedInstance().session() != nil) { if let shareEmailViewController = TWTRShareEmailViewController(completion: { (email: String!, error: NSError!) in if (email != nil) { print("\(email)") } else { print("\(error)") } }) { self.presentViewController(shareEmailViewController, animated: true, completion: nil) } } else { print("User not logged in") }