Skip to content

Commit

Permalink
Solve request review deprecated iOS (#53)
Browse files Browse the repository at this point in the history
* bump-version-minor

* upgrade request review to support iOS 14+

* impl. method isAvailable

* rename error name getting from activity android

* update README.md
  • Loading branch information
MinaSamir11 authored Jun 12, 2021
1 parent f437af4 commit b608e56
Show file tree
Hide file tree
Showing 10 changed files with 28,017 additions and 28,003 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ InAppReview.RequestInAppReview()
| ERROR_DEVICE_VERSION | 21 | This Device not supported to lanuch InAppReview |||
| GOOGLE_SERVICES_NOT_AVAILABLE | 22 | This Device doesn't support google play services |||
| [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. |||
| ACTIVITY_DOESN'T_EXIST | 24 | Unexpected error occur while getting activity |||
| SCENE_DOESN'T_EXIST | 25 | Unexpected error occur while getting scene |||


# + Android Notes:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void show(final Promise promise) {
Activity currentActivity = getCurrentActivity();

if (currentActivity == null) {
rejectPromise("24", new Error("Activity doesn't exist"));
rejectPromise("24", new Error("ACTIVITY_DOESN'T_EXIST"));
return;
}

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class InAppReview {
if (Platform.OS === 'android') {
return InAppReviewModule.show();
} else {
return RNInAppReviewIOS.requestReview({});
return RNInAppReviewIOS.requestReview();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@
#else
#import <React/RCTBridgeModule.h>
#endif

@interface RNInAppReviewIOS : NSObject <RCTBridgeModule>

@end
31 changes: 8 additions & 23 deletions ios/RNInAppReviewIOS.m
Original file line number Diff line number Diff line change
@@ -1,37 +1,22 @@
#import "RNInAppReviewIOS.h"
#import <Foundation/Foundation.h>
#import <StoreKit/SKStoreReviewController.h>
#import <UIKit/UIKit.h>
#import "RCTBridgeModule.h"

@implementation RNInAppReviewIOS

@interface RCT_EXTERN_MODULE(RNInAppReviewIOS, NSObject)

- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
}

RCT_EXPORT_MODULE()

- (NSDictionary *)constantsToExport
{
return @{
@"isAvailable": [SKStoreReviewController class] ? @(YES) : @(NO)
};
}

RCT_EXPORT_METHOD(requestReview:
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
if (@available(iOS 10.3, *)) {
[SKStoreReviewController requestReview];
resolve(@"true");
}else{
reject(@"21",@"ERROR_DEVICE_VERSION",nil);
}
}
RCT_EXTERN_METHOD(requestReview:
(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

+ (BOOL)requiresMainQueueSetup
{
return YES;
}

@end
@end
29 changes: 29 additions & 0 deletions ios/RNInAppReviewIOS.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Foundation
import UIKit
import StoreKit

@objc(RNInAppReviewIOS)
class RNInAppReviewIOS: NSObject {

@objc
func requestReview (_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
if #available(iOS 14.0, *) {
if let scene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene {
SKStoreReviewController.requestReview(in: scene)
resolve("true");
} else {
reject("25","SCENE_DOESN'T_EXIST",nil);
}
} else if #available(iOS 10.3, *) {
SKStoreReviewController.requestReview()
resolve("true");
} else {
reject("21","ERROR_DEVICE_VERSION",nil);
}
}

@objc
func constantsToExport() -> [String: Any]! {
return ["isAvailable": (NSClassFromString("SKStoreReviewController") != nil) ? (true) : (false)]
}
}
5 changes: 3 additions & 2 deletions ios/RNInAppReviewIOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@

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

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -50,7 +51,7 @@
58B511D21A9E6C8500147676 = {
isa = PBXGroup;
children = (
B3E7B5881CC2AC0600A0062D /* RNInAppReviewIOS.h */,
B3E7B5881CC2AC0600A0062D /* RNInAppReviewIOS-Bridging-Header.h */,
B3E7B5891CC2AC0600A0062D /* RNInAppReviewIOS.m */,
134814211AA4EA7D00B7C361 /* Products */,
);
Expand Down
Loading

0 comments on commit b608e56

Please sign in to comment.