55#import " qonversion_react_native_sdk-Swift.h"
66#endif
77
8+ #define QNR_LOG_EXCEPTION (method, exception ) \
9+ NSLog (@" [Qonversion] Caught NSException in %s : %@ — %@ " , method, exception.name, exception.reason)
10+
811@interface RNNoCodes () <NoCodesEventDelegate, NoCodesPurchaseDelegateProxy>
912
1013@property (nonatomic, strong) RNNoCodesImpl *impl;
@@ -22,79 +25,135 @@ - (instancetype)init {
2225 return self;
2326}
2427
28+ #pragma mark - Void Methods
29+
2530- (void )initialize : (NSString *)projectKey
2631 source : (NSString *)source
2732 version : (NSString *)version
2833 proxyUrl : (NSString *)proxyUrl
2934 locale : (NSString *)locale
3035 theme : (NSString *)theme {
31- [self .impl initializeWithProjectKey: projectKey source: source version: version proxyUrl: proxyUrl locale: locale theme: theme];
36+ @try {
37+ [self .impl initializeWithProjectKey: projectKey source: source version: version proxyUrl: proxyUrl locale: locale theme: theme];
38+ } @catch (NSException *exception) {
39+ QNR_LOG_EXCEPTION (" initialize" , exception);
40+ }
3241}
3342
3443- (void )setScreenPresentationConfig : (NSDictionary *)configData
3544 contextKey : (NSString *)contextKey
3645 resolve : (RCTPromiseResolveBlock)resolve
3746 reject : (RCTPromiseRejectBlock)reject {
38- [self .impl setScreenPresentationConfig: configData contextKey: contextKey];
47+ @try {
48+ [self .impl setScreenPresentationConfig: configData contextKey: contextKey];
49+ } @catch (NSException *exception) {
50+ QNR_LOG_EXCEPTION (" setScreenPresentationConfig" , exception);
51+ }
3952}
4053
4154- (void )showScreen : (NSString *)contextKey
4255 resolve : (RCTPromiseResolveBlock)resolve
4356 reject : (RCTPromiseRejectBlock)reject {
4457 dispatch_async (dispatch_get_main_queue (), ^{
45- [self .impl showScreenWithContextKey: contextKey];
58+ @try {
59+ [self .impl showScreenWithContextKey: contextKey];
60+ } @catch (NSException *exception) {
61+ QNR_LOG_EXCEPTION (" showScreen" , exception);
62+ }
4663 });
4764}
4865
4966- (void )close : (RCTPromiseResolveBlock)resolve
5067 reject : (RCTPromiseRejectBlock)reject {
5168 dispatch_async (dispatch_get_main_queue (), ^{
52- [self .impl close ];
69+ @try {
70+ [self .impl close ];
71+ } @catch (NSException *exception) {
72+ QNR_LOG_EXCEPTION (" close" , exception);
73+ }
5374 });
5475}
5576
5677- (void )setPurchaseDelegate {
57- [self .impl setPurchaseDelegate: self ];
78+ @try {
79+ [self .impl setPurchaseDelegate: self ];
80+ } @catch (NSException *exception) {
81+ QNR_LOG_EXCEPTION (" setPurchaseDelegate" , exception);
82+ }
5883}
5984
6085- (void )delegatedPurchaseCompleted {
61- [self .impl delegatedPurchaseCompleted ];
86+ @try {
87+ [self .impl delegatedPurchaseCompleted ];
88+ } @catch (NSException *exception) {
89+ QNR_LOG_EXCEPTION (" delegatedPurchaseCompleted" , exception);
90+ }
6291}
6392
6493- (void )delegatedPurchaseFailed : (NSString *)errorMessage {
65- [self .impl delegatedPurchaseFailed: errorMessage];
94+ @try {
95+ [self .impl delegatedPurchaseFailed: errorMessage];
96+ } @catch (NSException *exception) {
97+ QNR_LOG_EXCEPTION (" delegatedPurchaseFailed" , exception);
98+ }
6699}
67100
68101- (void )delegatedRestoreCompleted {
69- [self .impl delegatedRestoreCompleted ];
102+ @try {
103+ [self .impl delegatedRestoreCompleted ];
104+ } @catch (NSException *exception) {
105+ QNR_LOG_EXCEPTION (" delegatedRestoreCompleted" , exception);
106+ }
70107}
71108
72109- (void )delegatedRestoreFailed : (NSString *)errorMessage {
73- [self .impl delegatedRestoreFailed: errorMessage];
110+ @try {
111+ [self .impl delegatedRestoreFailed: errorMessage];
112+ } @catch (NSException *exception) {
113+ QNR_LOG_EXCEPTION (" delegatedRestoreFailed" , exception);
114+ }
74115}
75116
76117- (void )setLocale : (NSString *)locale {
77- [self .impl setLocale: locale];
118+ @try {
119+ [self .impl setLocale: locale];
120+ } @catch (NSException *exception) {
121+ QNR_LOG_EXCEPTION (" setLocale" , exception);
122+ }
78123}
79124
80125- (void )setTheme : (NSString *)theme {
81- [self .impl setTheme: theme];
126+ @try {
127+ [self .impl setTheme: theme];
128+ } @catch (NSException *exception) {
129+ QNR_LOG_EXCEPTION (" setTheme" , exception);
130+ }
82131}
83132
84- #pragma mark - NoCodesEventDelegate
133+ #pragma mark - Delegate Callbacks
85134
86135- (void )noCodesDidTriggerWithEvent : (NSString * _Nonnull)event payload : (NSDictionary <NSString *,id> * _Nullable)payload {
87- [self emitOnNoCodeEvent: @{@" name" : event, @" payload" : payload ?: [NSNull null ]}];
136+ @try {
137+ [self emitOnNoCodeEvent: @{@" name" : event, @" payload" : payload ?: [NSNull null ]}];
138+ } @catch (NSException *exception) {
139+ QNR_LOG_EXCEPTION (" noCodesDidTriggerWithEvent" , exception);
140+ }
88141}
89142
90- #pragma mark - NoCodesPurchaseDelegateProxy
91-
92143- (void )purchase : (NSDictionary *)product {
93- [self emitOnNoCodePurchase: product];
144+ @try {
145+ [self emitOnNoCodePurchase: product];
146+ } @catch (NSException *exception) {
147+ QNR_LOG_EXCEPTION (" purchase (NoCodes delegate)" , exception);
148+ }
94149}
95150
96151- (void )restore {
97- [self emitOnNoCodeRestore ];
152+ @try {
153+ [self emitOnNoCodeRestore ];
154+ } @catch (NSException *exception) {
155+ QNR_LOG_EXCEPTION (" restore (NoCodes delegate)" , exception);
156+ }
98157}
99158
100159#pragma mark - TurboModule
0 commit comments