Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 76 additions & 17 deletions ios/RNNoCodes.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#import "qonversion_react_native_sdk-Swift.h"
#endif

#define QNR_LOG_EXCEPTION(method, exception) \
NSLog(@"[Qonversion] Caught NSException in %s: %@ — %@", method, exception.name, exception.reason)

@interface RNNoCodes () <NoCodesEventDelegate, NoCodesPurchaseDelegateProxy>

@property (nonatomic, strong) RNNoCodesImpl *impl;
Expand All @@ -22,79 +25,135 @@ - (instancetype)init {
return self;
}

#pragma mark - Void Methods

- (void)initialize:(NSString *)projectKey
source:(NSString *)source
version:(NSString *)version
proxyUrl:(NSString *)proxyUrl
locale:(NSString *)locale
theme:(NSString *)theme {
[self.impl initializeWithProjectKey:projectKey source:source version:version proxyUrl:proxyUrl locale:locale theme:theme];
@try {
[self.impl initializeWithProjectKey:projectKey source:source version:version proxyUrl:proxyUrl locale:locale theme:theme];
} @catch (NSException *exception) {
QNR_LOG_EXCEPTION("initialize", exception);
}
}

- (void)setScreenPresentationConfig:(NSDictionary *)configData
contextKey:(NSString *)contextKey
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject {
[self.impl setScreenPresentationConfig:configData contextKey:contextKey];
@try {
[self.impl setScreenPresentationConfig:configData contextKey:contextKey];
} @catch (NSException *exception) {
QNR_LOG_EXCEPTION("setScreenPresentationConfig", exception);
}
}

- (void)showScreen:(NSString *)contextKey
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject {
dispatch_async(dispatch_get_main_queue(), ^{
[self.impl showScreenWithContextKey:contextKey];
@try {
[self.impl showScreenWithContextKey:contextKey];
} @catch (NSException *exception) {
QNR_LOG_EXCEPTION("showScreen", exception);
}
});
}

- (void)close:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject {
dispatch_async(dispatch_get_main_queue(), ^{
[self.impl close];
@try {
[self.impl close];
} @catch (NSException *exception) {
QNR_LOG_EXCEPTION("close", exception);
}
});
}

- (void)setPurchaseDelegate {
[self.impl setPurchaseDelegate:self];
@try {
[self.impl setPurchaseDelegate:self];
} @catch (NSException *exception) {
QNR_LOG_EXCEPTION("setPurchaseDelegate", exception);
}
}

- (void)delegatedPurchaseCompleted {
[self.impl delegatedPurchaseCompleted];
@try {
[self.impl delegatedPurchaseCompleted];
} @catch (NSException *exception) {
QNR_LOG_EXCEPTION("delegatedPurchaseCompleted", exception);
}
}

- (void)delegatedPurchaseFailed:(NSString *)errorMessage {
[self.impl delegatedPurchaseFailed:errorMessage];
@try {
[self.impl delegatedPurchaseFailed:errorMessage];
} @catch (NSException *exception) {
QNR_LOG_EXCEPTION("delegatedPurchaseFailed", exception);
}
}

- (void)delegatedRestoreCompleted {
[self.impl delegatedRestoreCompleted];
@try {
[self.impl delegatedRestoreCompleted];
} @catch (NSException *exception) {
QNR_LOG_EXCEPTION("delegatedRestoreCompleted", exception);
}
}

- (void)delegatedRestoreFailed:(NSString *)errorMessage {
[self.impl delegatedRestoreFailed:errorMessage];
@try {
[self.impl delegatedRestoreFailed:errorMessage];
} @catch (NSException *exception) {
QNR_LOG_EXCEPTION("delegatedRestoreFailed", exception);
}
}

- (void)setLocale:(NSString *)locale {
[self.impl setLocale:locale];
@try {
[self.impl setLocale:locale];
} @catch (NSException *exception) {
QNR_LOG_EXCEPTION("setLocale", exception);
}
}

- (void)setTheme:(NSString *)theme {
[self.impl setTheme:theme];
@try {
[self.impl setTheme:theme];
} @catch (NSException *exception) {
QNR_LOG_EXCEPTION("setTheme", exception);
}
}

#pragma mark - NoCodesEventDelegate
#pragma mark - Delegate Callbacks

- (void)noCodesDidTriggerWithEvent:(NSString * _Nonnull)event payload:(NSDictionary<NSString *,id> * _Nullable)payload {
[self emitOnNoCodeEvent:@{@"name": event, @"payload": payload ?: [NSNull null]}];
@try {
[self emitOnNoCodeEvent:@{@"name": event, @"payload": payload ?: [NSNull null]}];
} @catch (NSException *exception) {
QNR_LOG_EXCEPTION("noCodesDidTriggerWithEvent", exception);
}
}

#pragma mark - NoCodesPurchaseDelegateProxy

- (void)purchase:(NSDictionary *)product {
[self emitOnNoCodePurchase:product];
@try {
[self emitOnNoCodePurchase:product];
} @catch (NSException *exception) {
QNR_LOG_EXCEPTION("purchase (NoCodes delegate)", exception);
}
}

- (void)restore {
[self emitOnNoCodeRestore];
@try {
[self emitOnNoCodeRestore];
} @catch (NSException *exception) {
QNR_LOG_EXCEPTION("restore (NoCodes delegate)", exception);
}
}

#pragma mark - TurboModule
Expand Down
Loading