Skip to content

Commit

Permalink
fix: support for react native 0.76
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehan27 committed Nov 18, 2024
1 parent 831933b commit 5118d6f
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 112 deletions.
17 changes: 8 additions & 9 deletions ios/wrappers/CioRctWrapper.mm
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#import <React/RCTBridgeModule.h>

@interface RCT_EXTERN_REMAP_MODULE (NativeCustomerIO, CioRctWrapper, NSObject)

@interface RCT_EXTERN_REMAP_MODULE(NativeCustomerIO, CioRctWrapper, NSObject)

RCT_EXTERN_METHOD(initialize:(id)config args:(id)args)
RCT_EXTERN_METHOD(identify:(NSString *)identify traits:(NSDictionary *)traits)
RCT_EXTERN_METHOD(initialize : (id)config args : (id _Nullable)args)
RCT_EXTERN_METHOD(identify : (NSString* _Nullable)userId traits : (NSDictionary* _Nullable)traits)
RCT_EXTERN_METHOD(clearIdentify)
RCT_EXTERN_METHOD(track:(NSString *)name properties:(NSDictionary *)properties)
RCT_EXTERN_METHOD(screen:(NSString *)title properties:(NSDictionary *))
RCT_EXTERN_METHOD(setProfileAttributes: (NSDictionary *)attributes)
RCT_EXTERN_METHOD(setDeviceAttributes: (NSDictionary *)attributes)
RCT_EXTERN_METHOD(registerDeviceToken: (NSString *)token)
RCT_EXTERN_METHOD(track : (NSString*)name properties : (NSDictionary* _Nullable)properties)
RCT_EXTERN_METHOD(screen : (NSString*)title properties : (NSDictionary* _Nullable)properties)
RCT_EXTERN_METHOD(setProfileAttributes : (NSDictionary*)attributes)
RCT_EXTERN_METHOD(setDeviceAttributes : (NSDictionary*)attributes)
RCT_EXTERN_METHOD(registerDeviceToken : (NSString*)token)
RCT_EXTERN_METHOD(deleteDeviceToken)

+ (BOOL)requiresMainQueueSetup
Expand Down
63 changes: 31 additions & 32 deletions ios/wrappers/CioRctWrapper.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import CioInternalCommon
import CioAnalytics
import CioDataPipelines
import CioInternalCommon
import CioMessagingInApp
import CioMessagingPush
import UserNotifications
import React
import CioAnalytics
import UserNotifications

@objc(CioRctWrapper)
class CioRctWrapper: NSObject {

@objc var moduleRegistry: RCTModuleRegistry!
private let logger: CioInternalCommon.Logger = DIGraphShared.shared.logger

@objc(initialize:args:)
func initialize(_ configJson: AnyObject, _ sdkArgs: AnyObject?) {
do {
Expand All @@ -22,14 +21,14 @@ class CioRctWrapper: NSObject {
let sdkParams = sdkArgs as? [String: Any?]
let packageSource = sdkParams?["packageSource"] as? String
let packageVersion = sdkParams?["packageVersion"] as? String

if let source = packageSource, let sdkVersion = packageVersion {
DIGraphShared.shared.override(value: CustomerIOSdkClient(source: source, sdkVersion: sdkVersion), forType: SdkClient.self)
}

let sdkConfigBuilder = try SDKConfigBuilder.create(from: sdkConfig)
CustomerIO.initialize(withConfig: sdkConfigBuilder.build())

if let inAppConfig = try? MessagingInAppConfigBuilder.build(from: sdkConfig) {
MessagingInApp.initialize(withConfig: inAppConfig)
MessagingInApp.shared.setEventListener(self)
Expand All @@ -39,9 +38,9 @@ class CioRctWrapper: NSObject {
logger.error("Initializing Customer.io SDK failed with error: \(error)")
}
}
@objc
func identify(_ userId: String? = nil, traits: [String: Any]? = nil) {

@objc(identify:traits:)
func identify(_ userId: String?, _ traits: [String: Any]?) {
if let userId = userId {
CustomerIO.shared.identify(userId: userId, traits: traits)
} else if traits != nil {
Expand All @@ -54,39 +53,39 @@ class CioRctWrapper: NSObject {
logger.error("Provide id or traits to identify a user profile.")
}
}
@objc

@objc(clearIdentify)
func clearIdentify() {
CustomerIO.shared.clearIdentify()
}
@objc
func track(_ name: String, properties: [String: Any]?) {

@objc(track:properties:)
func track(_ name: String, _ properties: [String: Any]?) {
CustomerIO.shared.track(name: name, properties: properties)
}
@objc
func screen(_ title: String, properties: [String: Any]?) {

@objc(screen:properties:)
func screen(_ title: String, _ properties: [String: Any]?) {
CustomerIO.shared.screen(title: title, properties: properties)
}
@objc

@objc(setProfileAttributes:)
func setProfileAttributes(_ attrs: [String: Any]) {
CustomerIO.shared.profileAttributes = attrs
}
@objc

@objc(setDeviceAttributes:)
func setDeviceAttributes(_ attrs: [String: Any]) {
CustomerIO.shared.deviceAttributes = attrs
}
@objc
func registerDeviceToken(_ token: String){

@objc(registerDeviceToken:)
func registerDeviceToken(_ token: String) {
CustomerIO.shared.registerDeviceToken(token)
}
@objc
func deleteDeviceToken(){

@objc(deleteDeviceToken)
func deleteDeviceToken() {
CustomerIO.shared.deleteDeviceToken()
}
}
Expand All @@ -109,19 +108,19 @@ extension CioRctWrapper: InAppEventListener {
body: body
)
}

func messageShown(message: InAppMessage) {
sendEvent(eventType: CustomerioConstants.messageShown, message: message)
}

func messageDismissed(message: InAppMessage) {
sendEvent(eventType: CustomerioConstants.messageDismissed, message: message)
}

func errorWithMessage(message: InAppMessage) {
sendEvent(eventType: CustomerioConstants.errorWithMessage, message: message)
}

func messageActionTaken(message: InAppMessage, actionValue: String, actionName: String) {
sendEvent(eventType: CustomerioConstants.messageActionTaken, message: message, actionValue: actionValue, actionName: actionName)
}
Expand Down
2 changes: 1 addition & 1 deletion ios/wrappers/inapp/CioRctInAppMessaging.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import <React/RCTEventEmitter.h>

@interface RCT_EXTERN_REMAP_MODULE(CioRctInAppMessaging, CioRctInAppMessaging, RCTEventEmitter)
@interface RCT_EXTERN_REMAP_MODULE (CioRctInAppMessaging, CioRctInAppMessaging, RCTEventEmitter)

RCT_EXTERN_METHOD(supportedEvents)

Expand Down
6 changes: 3 additions & 3 deletions ios/wrappers/inapp/CioRctInAppMessaging.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CioMessagingInApp
import Foundation
import React
import CioMessagingInApp

@objc(CioRctInAppMessaging)
class CioRctInAppMessaging: RCTEventEmitter {
Expand All @@ -21,8 +21,8 @@ class CioRctInAppMessaging: RCTEventEmitter {
* Overriding supportedEvents method to return an array of supported event names.
* We are combining in-app events against single name so only one event is added.
*/
open override func supportedEvents() -> [String]! {
return [CustomerioConstants.inAppEventListener]
override open func supportedEvents() -> [String]! {
[CustomerioConstants.inAppEventListener]
}

/**
Expand Down
3 changes: 2 additions & 1 deletion ios/wrappers/logging/CioLoggingEmitter.mm
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import <React/RCTEventEmitter.h>

@interface RCT_EXTERN_REMAP_MODULE(CioLoggingEmitter, CioLoggingEmitter, RCTEventEmitter)
@interface RCT_EXTERN_REMAP_MODULE (CioLoggingEmitter, CioLoggingEmitter, RCTEventEmitter)

@end
28 changes: 13 additions & 15 deletions ios/wrappers/logging/CioLoggingEmitter.swift
Original file line number Diff line number Diff line change
@@ -1,51 +1,49 @@

import React
import CioInternalCommon
import React

@objc(CioLoggingEmitter)
class CioLoggingEmitter: RCTEventEmitter {

fileprivate static var eventName = "CioLogEvent"

fileprivate var hasObservers = false

// Requires adding requiresMainQueueSetup method
// since it overrides init
@objc static override func requiresMainQueueSetup() -> Bool {
return true // Return true if the module must be initialized on the main queue
@objc override static func requiresMainQueueSetup() -> Bool {
true // Return true if the module must be initialized on the main queue
}

override init() {
super.init()

DIGraphShared.shared.logger.setLogDispatcher { [weak self] level, message in
guard let self else { return }

emit(level: level, message: message)
}
}

deinit {
// Clear log dispatcher if the emitter has been deallocated
DIGraphShared.shared.logger.setLogDispatcher(nil)
}

override func startObserving() {
hasObservers = true
}

override func stopObserving() {
hasObservers = false
}

override func supportedEvents() -> [String] {
[Self.eventName]
}

override var methodQueue: dispatch_queue_t! {
DispatchQueue(label: Self.moduleName())
}

private var emitter: CioLoggingEmitter? {
moduleRegistry?.module(forName: "CioLoggingEmitter") as? CioLoggingEmitter
}
Expand Down
25 changes: 14 additions & 11 deletions ios/wrappers/push/CioRctPushMessaging.mm
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
#import <React/RCTBridgeModule.h>

@interface RCT_EXTERN_REMAP_MODULE(CioRctPushMessaging, CioRctPushMessaging, NSObject)
@interface RCT_EXTERN_REMAP_MODULE (CioRctPushMessaging, CioRctPushMessaging, NSObject)

RCT_EXTERN_METHOD(trackNotificationResponseReceived : (nonnull NSDictionary *) payload])
RCT_EXTERN_METHOD(trackNotificationResponseReceived : (NSDictionary*)payload)

RCT_EXTERN_METHOD(trackNotificationReceived : (nonnull NSDictionary *) payload])
RCT_EXTERN_METHOD(trackNotificationReceived : (NSDictionary*)payload)

RCT_EXTERN_METHOD(getRegisteredDeviceToken: (RCTPromiseResolveBlock) resolver
rejecter:(RCTPromiseRejectBlock)rejecter)
RCT_EXTERN_METHOD(getRegisteredDeviceToken
: (RCTPromiseResolveBlock)resolver rejecter
: (RCTPromiseRejectBlock)rejecter)

RCT_EXTERN_METHOD(showPromptForPushNotifications: (nonnull NSDictionary *) options
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(showPromptForPushNotifications
: (NSDictionary*)options resolver
: (RCTPromiseResolveBlock)resolve rejecter
: (RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(getPushPermissionStatus: (RCTPromiseResolveBlock) resolver
rejecter:(RCTPromiseRejectBlock)rejecter)
RCT_EXTERN_METHOD(getPushPermissionStatus
: (RCTPromiseResolveBlock)resolver rejecter
: (RCTPromiseRejectBlock)reject)

@end
@end
Loading

0 comments on commit 5118d6f

Please sign in to comment.