From ec61ebbb4796f62b9bf36aff79faac9b7095997d Mon Sep 17 00:00:00 2001 From: Denis Sedura Date: Sun, 28 Oct 2018 11:24:53 +0200 Subject: [PATCH 1/2] upgrade TwitterKit for iOS --- example/ios/Podfile | 2 +- example/ios/example/AppDelegate.m | 4 ++-- ios/TPSTwitterModule/TPSTwitterModule.m | 2 +- package.json | 2 +- scripts/post-link-ios.rb | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) 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..bbb137b 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" 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 From ad78a1f9432c6b6a3d063877d56a6047068a525b Mon Sep 17 00:00:00 2001 From: Denis Sedura Date: Sun, 28 Oct 2018 12:01:49 +0200 Subject: [PATCH 2/2] Getting email for current user --- .../TPSTwitterModule.java | 19 +++++++++++++++++++ ios/TPSTwitterModule/TPSTwitterModule.m | 13 +++++++++++++ 2 files changed, 32 insertions(+) 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/ios/TPSTwitterModule/TPSTwitterModule.m b/ios/TPSTwitterModule/TPSTwitterModule.m index bbb137b..4407c12 100644 --- a/ios/TPSTwitterModule/TPSTwitterModule.m +++ b/ios/TPSTwitterModule/TPSTwitterModule.m @@ -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 {