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

女生的网名这么多〃 提交于 2020-01-11 07:07:07

问题


I'd like to request the user's Twitter mail. On https://dev.twitter.com/twitter-kit/ios/request-email we can see the code in Obj-C but I need it in Swift and I can't translate it. Does anyone know how, please?

Here's the Obj-C code:

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)
}

Thanks for the help.


回答1:


This should roughly translate the above Objective-C to 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")
    }


来源:https://stackoverflow.com/questions/28679652/ask-for-user-twitter-mail-with-twtrshareemailviewcontroller-fabric-twitter-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!