diff --git a/android/src/main/java/com/gettipsi/reactnativetwittersdk/TPSTwitterModule.java b/android/src/main/java/com/gettipsi/reactnativetwittersdk/TPSTwitterModule.java index 0978a67..340b62c 100644 --- a/android/src/main/java/com/gettipsi/reactnativetwittersdk/TPSTwitterModule.java +++ b/android/src/main/java/com/gettipsi/reactnativetwittersdk/TPSTwitterModule.java @@ -19,6 +19,7 @@ import com.twitter.sdk.android.core.DefaultLogger; import com.twitter.sdk.android.core.Result; import com.twitter.sdk.android.core.Twitter; +import com.twitter.sdk.android.core.TwitterCore; import com.twitter.sdk.android.core.TwitterAuthConfig; import com.twitter.sdk.android.core.TwitterAuthToken; import com.twitter.sdk.android.core.TwitterConfig; @@ -93,6 +94,24 @@ public void failure(TwitterException exception) { } + @ReactMethod + public void getEmailForCurrentUser(final Promise promise) { + TwitterSession twitterSession = TwitterCore.getInstance().getSessionManager().getActiveSession(); + TwitterAuthClient authClient = new TwitterAuthClient(); + authClient.requestEmail(twitterSession, new Callback < String > () { + @Override + public void success(Result < String > result) { + promise.resolve(result.data); + } + + @Override + public void failure(TwitterException exception) { + promise.reject(TAG, exception.getMessage()); + } + }); + } + + @Override public void onHostResume() { if (currentData != null) { diff --git a/example/ios/Podfile b/example/ios/Podfile index c582bcd..2e327b2 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -2,5 +2,5 @@ platform :ios, '9.0' target 'example' do - pod 'TwitterKit', '3.1.1' + pod 'TwitterKit', '3.4.0' end diff --git a/example/ios/example/AppDelegate.m b/example/ios/example/AppDelegate.m index d3a7469..8ba1264 100644 --- a/example/ios/example/AppDelegate.m +++ b/example/ios/example/AppDelegate.m @@ -11,12 +11,12 @@ #import #import -#import +#import @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - + NSURL *jsCodeLocation; jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil]; diff --git a/ios/TPSTwitterModule/TPSTwitterModule.m b/ios/TPSTwitterModule/TPSTwitterModule.m index 1814533..4407c12 100644 --- a/ios/TPSTwitterModule/TPSTwitterModule.m +++ b/ios/TPSTwitterModule/TPSTwitterModule.m @@ -1,5 +1,5 @@ #import "TPSTwitterModule.h" -#import +#import #import #import #import "OAuthCore.h" @@ -130,6 +130,19 @@ - (NSDictionary *)errorCodesMap { } } +RCT_EXPORT_METHOD(getEmailForCurrentUser:(RCTPromiseResolveBlock)resolve + rejecter:(RCTPromiseRejectBlock)reject) { + TWTRAPIClient *client = [TWTRAPIClient clientWithCurrentUser]; + [client requestEmailForCurrentUser:^(NSString * _Nullable email, NSError * _Nullable error) { + if (error) { + NSError *rejectError = [self buildCannotLoadAccountErrorWithUnderlyingError:error]; + reject([self buildErrorCodeForError:rejectError], rejectError.localizedDescription, rejectError); + } else { + resolve(email); + } + }]; +} + #pragma mark - NSError - (NSError *)buildErrorWithCode:(NSInteger)code localizedDescription:(NSString *)localizedDescription { diff --git a/package.json b/package.json index 1836c40..53d14ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tipsi-twitter", - "version": "2.1.1", + "version": "2.1.2", "description": "Twitter sdk for react-native", "main": "src/index.js", "scripts": { diff --git a/scripts/post-link-ios.rb b/scripts/post-link-ios.rb index 5ca3f3c..cc2ebed 100644 --- a/scripts/post-link-ios.rb +++ b/scripts/post-link-ios.rb @@ -7,8 +7,8 @@ Dir.chdir('ios') @podfile_path = Pathname.pwd + 'Podfile' -@pod_dep_kit = " pod 'TwitterKit', '3.1.1'\n" -@pod_dep_core = " pod 'TwitterCore', '3.0.1'\n" +@pod_dep_kit = " pod 'TwitterKit', '3.4.0'\n" +@pod_dep_core = " pod 'TwitterCore', '3.2.0'\n" @project_paths= Pathname.pwd.children.select { |pn| pn.extname == '.xcodeproj' } raise 'No Xcode project found' unless @project_paths.length > 0