Skip to content

Commit b608e56

Browse files
authored
Solve request review deprecated iOS (MinaSamir11#53)
* bump-version-minor * upgrade request review to support iOS 14+ * impl. method isAvailable * rename error name getting from activity android * update README.md
1 parent f437af4 commit b608e56

File tree

10 files changed

+28017
-28003
lines changed

10 files changed

+28017
-28003
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ InAppReview.RequestInAppReview()
203203
| ERROR_DEVICE_VERSION | 21 | This Device not supported to lanuch InAppReview |||
204204
| GOOGLE_SERVICES_NOT_AVAILABLE | 22 | This Device doesn't support google play services |||
205205
| [DYNAMIC ERROR NAME] | 23 | Unexpected error occur may return different error from different user and device check code number to get discovered errors messages that could be happen. |||
206+
| ACTIVITY_DOESN'T_EXIST | 24 | Unexpected error occur while getting activity |||
207+
| SCENE_DOESN'T_EXIST | 25 | Unexpected error occur while getting scene |||
208+
206209

207210
# + Android Notes:
208211

android/src/main/java/com/ibits/react_native_in_app_review/AppReviewModule.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void show(final Promise promise) {
5151
Activity currentActivity = getCurrentActivity();
5252

5353
if (currentActivity == null) {
54-
rejectPromise("24", new Error("Activity doesn't exist"));
54+
rejectPromise("24", new Error("ACTIVITY_DOESN'T_EXIST"));
5555
return;
5656
}
5757

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default class InAppReview {
3030
if (Platform.OS === 'android') {
3131
return InAppReviewModule.show();
3232
} else {
33-
return RNInAppReviewIOS.requestReview({});
33+
return RNInAppReviewIOS.requestReview();
3434
}
3535
}
3636
}

ios/RNInAppReviewIOS.h renamed to ios/RNInAppReviewIOS-Bridging-Header.h

-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,3 @@
33
#else
44
#import <React/RCTBridgeModule.h>
55
#endif
6-
7-
@interface RNInAppReviewIOS : NSObject <RCTBridgeModule>
8-
9-
@end

ios/RNInAppReviewIOS.m

+8-23
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,22 @@
1-
#import "RNInAppReviewIOS.h"
1+
#import <Foundation/Foundation.h>
22
#import <StoreKit/SKStoreReviewController.h>
3+
#import <UIKit/UIKit.h>
4+
#import "RCTBridgeModule.h"
35

4-
@implementation RNInAppReviewIOS
5-
6+
@interface RCT_EXTERN_MODULE(RNInAppReviewIOS, NSObject)
67

78
- (dispatch_queue_t)methodQueue
89
{
910
return dispatch_get_main_queue();
1011
}
1112

12-
RCT_EXPORT_MODULE()
13-
14-
- (NSDictionary *)constantsToExport
15-
{
16-
return @{
17-
@"isAvailable": [SKStoreReviewController class] ? @(YES) : @(NO)
18-
};
19-
}
20-
21-
RCT_EXPORT_METHOD(requestReview:
22-
resolver:(RCTPromiseResolveBlock)resolve
23-
rejecter:(RCTPromiseRejectBlock)reject) {
24-
if (@available(iOS 10.3, *)) {
25-
[SKStoreReviewController requestReview];
26-
resolve(@"true");
27-
}else{
28-
reject(@"21",@"ERROR_DEVICE_VERSION",nil);
29-
}
30-
}
13+
RCT_EXTERN_METHOD(requestReview:
14+
(RCTPromiseResolveBlock)resolve
15+
rejecter:(RCTPromiseRejectBlock)reject)
3116

3217
+ (BOOL)requiresMainQueueSetup
3318
{
3419
return YES;
3520
}
3621

37-
@end
22+
@end

ios/RNInAppReviewIOS.swift

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
import UIKit
3+
import StoreKit
4+
5+
@objc(RNInAppReviewIOS)
6+
class RNInAppReviewIOS: NSObject {
7+
8+
@objc
9+
func requestReview (_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
10+
if #available(iOS 14.0, *) {
11+
if let scene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene {
12+
SKStoreReviewController.requestReview(in: scene)
13+
resolve("true");
14+
} else {
15+
reject("25","SCENE_DOESN'T_EXIST",nil);
16+
}
17+
} else if #available(iOS 10.3, *) {
18+
SKStoreReviewController.requestReview()
19+
resolve("true");
20+
} else {
21+
reject("21","ERROR_DEVICE_VERSION",nil);
22+
}
23+
}
24+
25+
@objc
26+
func constantsToExport() -> [String: Any]! {
27+
return ["isAvailable": (NSClassFromString("SKStoreReviewController") != nil) ? (true) : (false)]
28+
}
29+
}

ios/RNInAppReviewIOS.xcodeproj/project.pbxproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424

2525
/* Begin PBXFileReference section */
2626
134814201AA4EA6300B7C361 /* libRNInAppReviewIOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNInAppReviewIOS.a; sourceTree = BUILT_PRODUCTS_DIR; };
27-
B3E7B5881CC2AC0600A0062D /* RNInAppReviewIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNInAppReviewIOS.h; sourceTree = "<group>"; };
27+
B3E7B5881CC2AC0600A0062D /* RNInAppReviewIOS-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNInAppReviewIOS-Bridging-Header.h; sourceTree = "<group>"; };
2828
B3E7B5891CC2AC0600A0062D /* RNInAppReviewIOS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNInAppReviewIOS.m; sourceTree = "<group>"; };
29+
FA8B5363267515B100849ADB /* RNInAppReviewIOS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNInAppReviewIOS.swift; sourceTree = "<group>"; };
2930
/* End PBXFileReference section */
3031

3132
/* Begin PBXFrameworksBuildPhase section */
@@ -50,7 +51,7 @@
5051
58B511D21A9E6C8500147676 = {
5152
isa = PBXGroup;
5253
children = (
53-
B3E7B5881CC2AC0600A0062D /* RNInAppReviewIOS.h */,
54+
B3E7B5881CC2AC0600A0062D /* RNInAppReviewIOS-Bridging-Header.h */,
5455
B3E7B5891CC2AC0600A0062D /* RNInAppReviewIOS.m */,
5556
134814211AA4EA7D00B7C361 /* Products */,
5657
);

0 commit comments

Comments
 (0)