在 Swift 中使用 TWTRShareEmailViewController (Fabric Twitter SDK) 请求用户 Twitter 邮件

Ask for user Twitter mail with TWTRShareEmailViewController (Fabric Twitter SDK) in Swift

我想请求用户的 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 (e.g.
  // 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")
    }