Skip to content

Commit

Permalink
Added returning promise to identify method (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpertsyanKM authored May 7, 2024
1 parent 523b6b7 commit bfa40cf
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ repositories {
dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
implementation "io.qonversion.sandwich:sandwich:4.3.2"
implementation "io.qonversion.sandwich:sandwich:4.4.1"
}

afterEvaluate { project ->
Expand Down
4 changes: 2 additions & 2 deletions android/src/main/java/com/reactlibrary/QonversionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ public void syncPurchases() {
}

@ReactMethod
public void identify(String userID) {
qonversionSandwich.identify(userID);
public void identify(final String userID, final Promise promise) {
qonversionSandwich.identify(userID, Utils.getResultListener(promise));
}

@ReactMethod
Expand Down
20 changes: 10 additions & 10 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ PODS:
- glog (0.3.5)
- libevent (2.1.12)
- OpenSSL-Universal (1.1.1100)
- Qonversion (5.8.3):
- Qonversion/Main (= 5.8.3)
- Qonversion/Main (5.8.3)
- QonversionSandwich (4.3.1):
- Qonversion (= 5.8.3)
- Qonversion (5.9.0):
- Qonversion/Main (= 5.9.0)
- Qonversion/Main (5.9.0)
- QonversionSandwich (4.4.1):
- Qonversion (= 5.9.0)
- RCT-Folly (2021.07.22.00):
- boost
- DoubleConversion
Expand Down Expand Up @@ -289,8 +289,8 @@ PODS:
- React-jsinspector (0.70.5)
- React-logger (0.70.5):
- glog
- react-native-qonversion (7.1.0):
- QonversionSandwich (= 4.3.1)
- react-native-qonversion (7.2.0):
- QonversionSandwich (= 4.4.1)
- React
- React-perflogger (0.70.5)
- React-RCTActionSheet (0.70.5):
Expand Down Expand Up @@ -534,8 +534,8 @@ SPEC CHECKSUMS:
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
Qonversion: 336218b8b6776f415b5b8219e6b3e71faea47ff0
QonversionSandwich: 3e315bc74a92bb921dd3931a9a518cc5190e29bc
Qonversion: 2bba69076355a256e12ef372ff7ea4c1a3d5a054
QonversionSandwich: ec794430070a687b7eaf450211f3b8a108c26d50
RCT-Folly: 0080d0a6ebf2577475bda044aa59e2ca1f909cda
RCTRequired: 21229f84411088e5d8538f21212de49e46cc83e2
RCTTypeSafety: 62eed57a32924b09edaaf170a548d1fc96223086
Expand All @@ -550,7 +550,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: 31564fa6912459921568e8b0e49024285a4d584b
React-jsinspector: badd81696361249893a80477983e697aab3c1a34
React-logger: fdda34dd285bdb0232e059b19d9606fa0ec3bb9c
react-native-qonversion: 5b9e8604dff1fc444aa365777c6e4ea98c3507f6
react-native-qonversion: 280d063073ae59575c5a06bbbd2617f42517c48f
React-perflogger: e68d3795cf5d247a0379735cbac7309adf2fb931
React-RCTActionSheet: 05452c3b281edb27850253db13ecd4c5a65bc247
React-RCTAnimation: 578eebac706428e68466118e84aeacf3a282b4da
Expand Down
4 changes: 4 additions & 0 deletions example/ios/example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,12 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-example/Pods-example-resources.sh",
"${PODS_CONFIGURATION_BUILD_DIR}/Qonversion/Qonversion.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/React-Core/AccessibilityResources.bundle",
);
name = "[CP] Copy Pods Resources";
outputPaths = (
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/Qonversion.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AccessibilityResources.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -554,10 +556,12 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-example-exampleTests/Pods-example-exampleTests-resources.sh",
"${PODS_CONFIGURATION_BUILD_DIR}/Qonversion/Qonversion.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/React-Core/AccessibilityResources.bundle",
);
name = "[CP] Copy Pods Resources";
outputPaths = (
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/Qonversion.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AccessibilityResources.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
18 changes: 10 additions & 8 deletions ios/RNQonversion.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,26 @@ + (BOOL)requiresMainQueueSetup
}];
}

RCT_EXPORT_METHOD(identify:(NSString *)userId) {
[_qonversionSandwich identify:userId];
RCT_EXPORT_METHOD(identify:(NSString *)userId completion:(RCTResponseSenderBlock)completion rejecter:(RCTPromiseRejectBlock)reject) {
[_qonversionSandwich identify:userId :^(NSDictionary<NSString *,id> * _Nullable result, SandwichError * _Nullable error) {
[self handleResult:result error:error completion:completion rejecter:reject];
}];
}

RCT_EXPORT_METHOD(logout) {
[_qonversionSandwich logout];
}

RCT_EXPORT_METHOD(userInfo:(RCTResponseSenderBlock)completion rejecter:(RCTPromiseRejectBlock)reject) {
[_qonversionSandwich userInfo:^(NSDictionary<NSString *,id> * _Nullable result, SandwichError * _Nullable error) {
[self handleResult:result error:error completion:completion rejecter:reject];
}];
[_qonversionSandwich userInfo:^(NSDictionary<NSString *,id> * _Nullable result, SandwichError * _Nullable error) {
[self handleResult:result error:error completion:completion rejecter:reject];
}];
}

RCT_EXPORT_METHOD(remoteConfig:(NSString *)contextKey completion:(RCTResponseSenderBlock)completion rejecter:(RCTPromiseRejectBlock)reject) {
[_qonversionSandwich remoteConfig:contextKey :^(NSDictionary<NSString *,id> * _Nullable result, SandwichError * _Nullable error) {
[self handleResult:result error:error completion:completion rejecter:reject];
}];
[_qonversionSandwich remoteConfig:contextKey :^(NSDictionary<NSString *,id> * _Nullable result, SandwichError * _Nullable error) {
[self handleResult:result error:error completion:completion rejecter:reject];
}];
}

RCT_EXPORT_METHOD(remoteConfigList:(RCTResponseSenderBlock)completion rejecter:(RCTPromiseRejectBlock)reject) {
Expand Down
2 changes: 1 addition & 1 deletion react-native-qonversion.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ Pod::Spec.new do |s|
s.requires_arc = true

s.dependency "React"
s.dependency "QonversionSandwich", "4.3.2"
s.dependency "QonversionSandwich", "4.4.1"
end
3 changes: 2 additions & 1 deletion src/QonversionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ interface QonversionApi {
* Call this function to link a user to his unique ID in your system and share purchase data.
*
* @param userID unique user ID in your system
* @returns the promise with the information about the identified user.
*/
identify(userID: string): void;
identify(userID: string): Promise<User>;

/**
* Call this function to unlink a user from his unique ID in your system and his purchase data.
Expand Down
7 changes: 5 additions & 2 deletions src/internal/QonversionInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,11 @@ export default class QonversionInternal implements QonversionApi {
RNQonversion.syncPurchases();
}

identify(userID: string) {
RNQonversion.identify(userID);
async identify(userID: string): Promise<User> {
const userInfo = await RNQonversion.identify(userID);
const mappedUserInfo: User = Mapper.convertUserInfo(userInfo);

return mappedUserInfo;
}

logout() {
Expand Down

0 comments on commit bfa40cf

Please sign in to comment.