问题
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