diff --git a/UnitTests/MParticle+PrivateMethods.h b/UnitTests/MParticle+PrivateMethods.h index d6a0c6d94..5958739be 100644 --- a/UnitTests/MParticle+PrivateMethods.h +++ b/UnitTests/MParticle+PrivateMethods.h @@ -35,6 +35,9 @@ - (void)setKitContainer:(id) kitContainer; - (void)forwardLogInstall; - (void)forwardLogUpdate; +- (void)setUploadInterval:(NSTimeInterval)uploadInterval; +- (NSTimeInterval)uploadInterval; +- (NSDictionary *)userAttributesForUserId:(NSNumber *)userId; @property (nonatomic, strong, nonnull) id backendController; @property (nonatomic, strong) id settingsProvider; diff --git a/UnitTests/MParticleTestsSwift.swift b/UnitTests/MParticleTestsSwift.swift index 4bc737ea4..e622d2243 100644 --- a/UnitTests/MParticleTestsSwift.swift +++ b/UnitTests/MParticleTestsSwift.swift @@ -17,7 +17,7 @@ class MParticleTestsSwift: XCTestCase { override func setUp() { super.setUp() - mparticle = MParticle.sharedInstance() + mparticle = MParticle() mparticle.logLevel = .verbose mparticle.customLogger = customLogger listenerController = MPListenerControllerMock() @@ -778,4 +778,111 @@ class MParticleTestsSwift: XCTestCase { XCTAssertNil(kitContainer.forwardSDKCallParametersParam) XCTAssertNil(kitContainer.forwardSDKCallUserInfoParam) } + + func testIndentityReturnsTheSameObject() { + let identity = mparticle.identity + XCTAssertTrue(identity === mparticle.identity) + } + + func testRoktReturnsTheSameObject() { + let rokt = mparticle.rokt + XCTAssertTrue(rokt === mparticle.rokt) + } + + func testSessionTimeoutReturnsValueFromBackendController() { + let backendController = MPBackendControllerMock() + mparticle.backendController = backendController + mparticle.backendController.sessionTimeout = 100 + XCTAssertEqual(mparticle.sessionTimeout, 100) + } + + func testUniqueIdentifierRwturnedFromStateMachine() { + let stateMachine = MPStateMachineMock() + stateMachine.consumerInfo.uniqueIdentifier = "test" + mparticle.stateMachine = stateMachine + XCTAssertEqual(mparticle.uniqueIdentifier, "test") + } + + func testSetUploadIntervalChangeValueInBackendControllerWhenIntervalGreaterThenOne() { + let backendController = MPBackendControllerMock() + mparticle.backendController = backendController + mparticle.setUploadInterval(3) + XCTAssertEqual(backendController.uploadInterval, 3) + } + + func testSetUploadIntervalNotChangeValueInBackendControllerWhenIntervalLessThenOne() { + let backendController = MPBackendControllerMock() + mparticle.backendController = backendController + mparticle.setUploadInterval(0.1) + XCTAssertEqual(backendController.uploadInterval, 0.0) + } + + func testUploadIntervalGetFromBackendController() { + let backendController = MPBackendControllerMock() + mparticle.backendController = backendController + backendController.uploadInterval = 100 + XCTAssertEqual(mparticle.uploadInterval, 100) + } + + func testUserAttributesForUserIdRequestDataFromBackendController() { + let backendController = MPBackendControllerMock() + mparticle.backendController = backendController + + backendController.userAttributesReturnValue = ["key": "value"] + let dictionary = mparticle.userAttributes(forUserId: 1) + XCTAssertEqual(dictionary?["key"] as? String, "value") + XCTAssertTrue(backendController.userAttributesCalled) + XCTAssertEqual(backendController.userAttributesUserIdParam, 1) + } + + func testConfigureWithOptionsNoSettings() { + let backendController = MPBackendControllerMock() + let settingsProvider = SettingsProviderMock() + mparticle.settingsProvider = settingsProvider + mparticle.backendController = backendController + mparticle.configure(with: .init()) + XCTAssertEqual(backendController.sessionTimeout, 0.0) + XCTAssertEqual(backendController.uploadInterval, 0.0) + XCTAssertNil(mparticle.customUserAgent) + XCTAssertTrue(mparticle.collectUserAgent) + XCTAssertTrue(mparticle.trackNotifications) +#if os(iOS) +#if !MPARTICLE_LOCATION_DISABLE + XCTAssertNil(listenerController.onAPICalledApiName) +#endif +#endif + } + + func testConfigureWithOptionsWithSettingsAndOptionNotSet() { + let backendController = MPBackendControllerMock() + let settingsProvider = SettingsProviderMock() + mparticle.settingsProvider = settingsProvider + settingsProvider.configSettings = [ + "session_timeout": 100, + "upload_interval": 50, + "custom_user_agent": "agent", + "collect_user_agent": false, + "track_notifications": false, + "enable_location_tracking": true + ] + mparticle.backendController = backendController + let options = MParticleOptions() + options.isSessionTimeoutSet = false + options.isUploadIntervalSet = false + options.isCollectUserAgentSet = false + options.isCollectUserAgentSet = false + options.isTrackNotificationsSet = false + mparticle.configure(with: .init()) + XCTAssertEqual(backendController.sessionTimeout, 100.0) + XCTAssertEqual(backendController.uploadInterval, 50.0) + XCTAssertEqual(mparticle.customUserAgent, "agent") + XCTAssertFalse(mparticle.collectUserAgent) + XCTAssertFalse(mparticle.trackNotifications) + +#if os(iOS) +#if !MPARTICLE_LOCATION_DISABLE + XCTAssertEqual(listenerController.onAPICalledApiName?.description, "beginLocationTracking:minDistance:authorizationRequest:") +#endif +#endif + } } diff --git a/mParticle-Apple-SDK/Logger/MPLogger.swift b/mParticle-Apple-SDK/Logger/MPLogger.swift index a2911f590..6d2462516 100644 --- a/mParticle-Apple-SDK/Logger/MPLogger.swift +++ b/mParticle-Apple-SDK/Logger/MPLogger.swift @@ -37,18 +37,41 @@ public class MPLog: NSObject { MPLogger(loggerLevel: .verbose, format: format, arguments: arguments) } + public var logLevel: MPILogLevel + public var customLogger: ((String) -> Void)? + + public init(logLevel: MPILogLevel) { + self.logLevel = logLevel + } + + private func log(loggerLevel: MPILogLevel, format: String, arguments: any CVarArg...) { + if (logLevel.rawValue >= loggerLevel.rawValue && loggerLevel != .none) { + let msg = String.localizedStringWithFormat("mParticle -> \(format)", arguments) + if let customLogger = customLogger { + customLogger(msg) + } else { + NSLog(msg) + } + } + } + + @objc + public func error(_ message: String) { + log(loggerLevel: .error, format: message) + } + @objc - public static func error(message: String) { - error(message) + public func warning(_ message: String) { + log(loggerLevel: .warning, format: message) } @objc - public static func warning(message: String) { - warning(message) + public func debug(_ message: String) { + log(loggerLevel: .debug, format: message) } @objc - public static func debug(message: String) { - debug(message) + public func verbose(_ message: String) { + log(loggerLevel: .verbose, format: message) } } diff --git a/mParticle-Apple-SDK/mParticle.m b/mParticle-Apple-SDK/mParticle.m index 7aefdc3b7..b76fc1f7f 100644 --- a/mParticle-Apple-SDK/mParticle.m +++ b/mParticle-Apple-SDK/mParticle.m @@ -96,6 +96,7 @@ @implementation MParticle @synthesize settingsProvider = _settingsProvider; @synthesize listenerController = _listenerController; static id executor; +MPLog* logger; + (void)initialize { if (self == [MParticle class]) { @@ -147,6 +148,7 @@ - (instancetype)init { _stateMachine = [[MPStateMachine_PRIVATE alloc] init]; _webView = [[MParticleWebView_PRIVATE alloc] initWithMessageQueue:executor.messageQueue]; _listenerController = MPListenerController.sharedInstance; + logger = [[MPLog alloc] initWithLogLevel:_stateMachine.logLevel]; return self; } @@ -233,7 +235,13 @@ - (MPILogLevel)logLevel { return self.stateMachine.logLevel; } +- (void)setCustomLogger:(void (^)(NSString * _Nonnull))customLogger { + _customLogger = customLogger; + logger.customLogger = customLogger; +} + - (void)setLogLevel:(MPILogLevel)logLevel { + logger.logLevel = logLevel; self.stateMachine.logLevel = logLevel; } @@ -244,10 +252,10 @@ - (BOOL)optOut { - (void)setOptOutCompletion:(MPExecStatus)execStatus optOut:(BOOL)optOut { if (execStatus == MPExecStatusSuccess) { NSString* message = [NSString stringWithFormat:@"Set Opt Out: %d", optOut]; - [MPLog debugWithMessage:message]; + [logger debug:message]; } else { NSString* message = [NSString stringWithFormat:@"Set Opt Out Failed: %lu", (unsigned long)execStatus]; - [MPLog debugWithMessage:message]; + [logger debug:message]; } } @@ -334,7 +342,7 @@ - (void)identifyNoDispatchCallback:(MPIdentityApiResult * _Nullable)apiResult options:(MParticleOptions * _Nonnull)options { if (error) { NSString* message = [NSString stringWithFormat: @"Identify request failed with error: %@", error]; - [MPLog errorWithMessage:message]; + [logger error:message]; } NSArray *deferredKitConfiguration = self.deferredKitConfiguration_PRIVATE; @@ -408,7 +416,7 @@ - (void)startWithKeyCallback:(BOOL)firstRun [userDefaults synchronize]; } - self->_optOut = [MParticle sharedInstance].stateMachine.optOut; + self->_optOut = self.stateMachine.optOut; [self configureWithOptions:options]; @@ -488,9 +496,9 @@ - (void)startWithOptions:(MParticleOptions *)options { [userDefaults setSharedGroupIdentifier:self.options.sharedGroupID]; if (environment == MPEnvironmentDevelopment) { - [MPLog warningWithMessage:@"SDK has been initialized in Development mode."]; + [logger warning:@"SDK has been initialized in Development mode."]; } else if (environment == MPEnvironmentProduction) { - [MPLog warningWithMessage:@"SDK has been initialized in Production Mode."]; + [logger warning:@"SDK has been initialized in Production Mode."]; } [MPStateMachine_PRIVATE setEnvironment:environment]; @@ -718,7 +726,7 @@ - (nullable NSSet *)activeTimedEvents { - (void)beginTimedEventCompletionHandler:(MPEvent *)event execStatus:(MPExecStatus)execStatus { if (execStatus == MPExecStatusSuccess) { NSString *message = [NSString stringWithFormat:@"Began timed event: %@", event]; - [MPLog debugWithMessage:message]; + [logger debug:message]; MPEvent *kitEvent = self.dataPlanFilter != nil ? [self.dataPlanFilter transformEventForEvent:event] : event; if (kitEvent) { @@ -733,7 +741,7 @@ - (void)beginTimedEventCompletionHandler:(MPEvent *)event execStatus:(MPExecStat }]; } else { NSString *message = [NSString stringWithFormat:@"Blocked timed event begin from kits: %@", event]; - [MPLog debugWithMessage:message]; + [logger debug:message]; } } } @@ -769,7 +777,7 @@ - (void)logEventCallback:(MPEvent *)event execStatus:(MPExecStatus)execStatus { }]; } else { NSString *message = [NSString stringWithFormat:@"Blocked timed event end from kits: %@", event]; - [MPLog debugWithMessage:message]; + [logger debug:message]; } } } @@ -792,7 +800,7 @@ - (MPEvent *)eventWithName:(NSString *)eventName { - (void)logEvent:(MPBaseEvent *)event { if (event == nil) { - [MPLog errorWithMessage: @"Cannot log nil event!"]; + [logger error:@"Cannot log nil event!"]; } else if ([event isKindOfClass:[MPEvent class]]) { [self logCustomEvent:(MPEvent *)event]; } else if ([event isKindOfClass:[MPCommerceEvent class]]) { @@ -820,7 +828,7 @@ - (void)logEvent:(MPBaseEvent *)event { }]; } else { NSString *message = [NSString stringWithFormat:@"Blocked base event from kits: %@", event]; - [MPLog debugWithMessage:message]; + [logger debug:message]; } }]; } @@ -828,7 +836,7 @@ - (void)logEvent:(MPBaseEvent *)event { - (void)logCustomEvent:(MPEvent *)event { if (event == nil) { - [MPLog errorWithMessage:@"Cannot log nil event!"]; + [logger error:@"Cannot log nil event!"]; return; } @@ -853,7 +861,7 @@ - (void)logCustomEvent:(MPEvent *)event { }]; } else { NSString *message = [NSString stringWithFormat:@"Blocked custom event from kits: %@", event]; - [MPLog debugWithMessage:message]; + [logger debug:message]; } }]; @@ -861,7 +869,7 @@ - (void)logCustomEvent:(MPEvent *)event { - (void)logKitBatch:(NSString *)batch { if (batch == nil) { - [MPLog errorWithMessage:@"Cannot log nil batch!"]; + [logger error:@"Cannot log nil batch!"]; return; } @@ -919,7 +927,7 @@ - (void)logEvent:(NSString *)eventName eventType:(MPEventType)eventType eventInf - (void)logScreenCallback:(MPEvent *)event execStatus:(MPExecStatus)execStatus { if (execStatus == MPExecStatusSuccess) { NSString *message = [NSString stringWithFormat:@"Logged screen event: %@", event]; - [MPLog debugWithMessage:message]; + [logger debug:message]; MPEvent *kitEvent = self.dataPlanFilter != nil ? [self.dataPlanFilter transformEventForScreenEvent:event] : event; if (kitEvent) { @@ -934,14 +942,14 @@ - (void)logScreenCallback:(MPEvent *)event execStatus:(MPExecStatus)execStatus { }]; } else { NSString *message = [NSString stringWithFormat:@"Blocked screen event from kits: %@", event]; - [MPLog debugWithMessage:message]; + [logger debug:message]; } } } - (void)logScreenEvent:(MPEvent *)event { if (event == nil) { - [MPLog errorWithMessage:@"Cannot log nil screen event!"]; + [logger error:@"Cannot log nil screen event!"]; return; } if (!event.timestamp) { @@ -964,7 +972,7 @@ - (void)logScreen:(NSString *)screenName eventInfo:(NSDictionary - (void)logScreen:(NSString *)screenName eventInfo:(NSDictionary *)eventInfo shouldUploadEvent:(BOOL)shouldUploadEvent { if (!screenName) { - [MPLog errorWithMessage:@"Screen name is required."]; + [logger error:@"Screen name is required."]; return; } @@ -1015,7 +1023,7 @@ - (void)leaveBreadcrumb:(NSString *)breadcrumbName { - (void)leaveBreadcrumbCallback:(MPEvent *)event execStatus:(MPExecStatus)execStatus { if (execStatus == MPExecStatusSuccess) { NSString *message = [NSString stringWithFormat:@"Left breadcrumb: %@", event]; - [MPLog debugWithMessage:message]; + [logger debug:message]; MPEvent *kitEvent = self.dataPlanFilter != nil ? [self.dataPlanFilter transformEventForEvent:event] : event; if (kitEvent) { @@ -1030,14 +1038,14 @@ - (void)leaveBreadcrumbCallback:(MPEvent *)event execStatus:(MPExecStatus)execSt }]; } else { NSString *message = [NSString stringWithFormat:@"Blocked breadcrumb event from kits: %@", event]; - [MPLog debugWithMessage:message]; + [logger debug:message]; } } } - (void)leaveBreadcrumb:(NSString *)breadcrumbName eventInfo:(NSDictionary *)eventInfo { if (!breadcrumbName) { - [MPLog errorWithMessage:@"Breadcrumb name is required."]; + [logger error:@"Breadcrumb name is required."]; return; } @@ -1069,7 +1077,7 @@ - (void)logError:(NSString *)message { - (void)logErrorCallback:(NSDictionary * _Nullable)eventInfo execStatus:(MPExecStatus)execStatus message:(NSString *)message { if (execStatus == MPExecStatusSuccess) { NSString *debugMessage = [NSString stringWithFormat:@"Logged error with message: %@", message]; - [MPLog debugWithMessage:debugMessage]; + [logger debug:debugMessage]; // Forwarding calls to kits MPForwardQueueParameters *queueParameters = [[MPForwardQueueParameters alloc] init]; @@ -1088,7 +1096,7 @@ - (void)logErrorCallback:(NSDictionary * _Nullable)eventInfo exec - (void)logError:(NSString *)message eventInfo:(NSDictionary *)eventInfo { if (!message) { NSString *message = [NSString stringWithFormat:@"'message' is required for %@", NSStringFromSelector(_cmd)]; - [MPLog errorWithMessage:message]; + [logger error:message]; return; } @@ -1112,7 +1120,7 @@ - (void)logException:(NSException *)exception { - (void)logExceptionCallback:(NSException * _Nonnull)exception execStatus:(MPExecStatus)execStatus message:(NSString *)message topmostContext:(id _Nullable)topmostContext { if (execStatus == MPExecStatusSuccess) { NSString *debugMessage = [NSString stringWithFormat:@"Logged exception name: %@, reason: %@, topmost context: %@", message, exception.reason, topmostContext]; - [MPLog debugWithMessage:debugMessage]; + [logger debug:debugMessage]; // Forwarding calls to kits MPForwardQueueParameters *queueParameters = [[MPForwardQueueParameters alloc] init]; @@ -1144,7 +1152,7 @@ - (void)logException:(NSException *)exception topmostContext:(id)topmostContext - (void)logCrashCallback:(MPExecStatus)execStatus message:(NSString * _Nullable)message { if (execStatus == MPExecStatusSuccess) { NSString *debugMessage = [NSString stringWithFormat:@"Logged crash with message: %@", message]; - [MPLog debugWithMessage:debugMessage]; + [logger debug:debugMessage]; } } @@ -1154,7 +1162,7 @@ - (void)logCrash:(nullable NSString *)message { if (!plCrashReport) { NSString *message = [NSString stringWithFormat:@"'plCrashReport' is required for %@", NSStringFromSelector(_cmd)]; - [MPLog errorWithMessage:message]; + [logger error:message]; return; } @@ -1175,13 +1183,13 @@ - (void)logCommerceEventCallback:(MPCommerceEvent *)commerceEvent execStatus:(MP if (execStatus == MPExecStatusSuccess) { } else { NSString *message = [NSString stringWithFormat:@"Failed to log commerce event: %@", commerceEvent]; - [MPLog debugWithMessage:message]; + [logger debug:message]; } } - (void)logCommerceEvent:(MPCommerceEvent *)commerceEvent { if (commerceEvent == nil) { - [MPLog errorWithMessage:@"Cannot log nil commerce event!"]; + [logger error:@"Cannot log nil commerce event!"]; return; } if (!commerceEvent.timestamp) { @@ -1202,7 +1210,7 @@ - (void)logCommerceEvent:(MPCommerceEvent *)commerceEvent { [self.kitContainer forwardCommerceEventCall:kitEvent]; } else { NSString *message = [NSString stringWithFormat:@"Blocked commerce event from kits: %@", commerceEvent]; - [MPLog debugWithMessage:message]; + [logger debug:message]; } }]; } @@ -1226,7 +1234,7 @@ - (void)logLTVIncreaseCallback:(MPEvent *)event execStatus:(MPExecStatus)execSta }]; } else { NSString* message = [NSString stringWithFormat:@"Blocked LTV increase event from kits: %@", event]; - [MPLog debugWithMessage:message]; + [logger debug:message]; } } } @@ -1370,7 +1378,7 @@ - (void)setBackgroundLocationTracking:(BOOL)backgroundLocationTracking { #ifndef MPARTICLE_LOCATION_DISABLE [MParticle sharedInstance].stateMachine.locationManager.backgroundLocationTracking = backgroundLocationTracking; #else - [MPLog debugWithMessage:@"Automatic background tracking has been disabled to support users excluding location services from their applications."]; + [logger debug:@"Automatic background tracking has been disabled to support users excluding location services from their applications."]; #endif } @@ -1385,7 +1393,7 @@ - (void)setLocation:(CLLocation *)location { if (![self.stateMachine.location isEqual:location]) { self.stateMachine.location = location; NSString *message = [NSString stringWithFormat:@"Set location %@", location]; - [MPLog debugWithMessage:message]; + [logger debug:message]; [executor executeOnMain: ^{ [self.listenerController onAPICalled:_cmd parameter1:location]; @@ -1418,10 +1426,10 @@ - (void)beginLocationTracking:(CLLocationAccuracy)accuracy minDistance:(CLLocati MPExecStatus execStatus = [_backendController beginLocationTrackingWithAccuracy:accuracy distanceFilter:distanceFilter authorizationRequest:authorizationRequest]; if (execStatus == MPExecStatusSuccess) { NSString *message = [NSString stringWithFormat:@"Began location tracking with accuracy: %0.0f and distance filter %0.0f", accuracy, distanceFilter]; - [MPLog debugWithMessage:message]; + [logger debug:message]; } else { NSString *message = [NSString stringWithFormat:@"Could not begin location tracking: %@", [MPBackendController_PRIVATE execStatusDescription:execStatus]]; - [MPLog errorWithMessage:message]; + [logger error:message]; } } @@ -1430,10 +1438,10 @@ - (void)endLocationTracking { MPExecStatus execStatus = [_backendController endLocationTracking]; if (execStatus == MPExecStatusSuccess) { - [MPLog debugWithMessage:@"Ended location tracking"]; + [logger debug:@"Ended location tracking"]; } else { NSString *message = [NSString stringWithFormat:@"Could not end location tracking: %@", [MPBackendController_PRIVATE execStatusDescription:execStatus]]; - [MPLog errorWithMessage:message]; + [logger error:message]; } } #endif // MPARTICLE_LOCATION_DISABLE @@ -1441,7 +1449,7 @@ - (void)endLocationTracking { - (void)logNetworkPerformanceCallback:(MPExecStatus)execStatus { if (execStatus == MPExecStatusSuccess) { - [MPLog debugWithMessage:@"Logged network performance measurement"]; + [logger debug:@"Logged network performance measurement"]; } } @@ -1473,7 +1481,7 @@ - (NSNumber *)incrementSessionAttribute:(NSString *)key byValue:(NSNumber *)valu NSNumber *newValue = [self.backendController incrementSessionAttribute:[MParticle sharedInstance].stateMachine.currentSession key:key byValue:value]; NSString *message = [NSString stringWithFormat:@"Session attribute %@ incremented by %@. New value: %@", key, value, newValue]; - [MPLog debugWithMessage:message]; + [logger debug:message]; }]; return @0; @@ -1486,10 +1494,10 @@ - (void)setSessionAttribute:(NSString *)key value:(id)value { MPExecStatus execStatus = [self.backendController setSessionAttribute:[MParticle sharedInstance].stateMachine.currentSession key:key value:value]; if (execStatus == MPExecStatusSuccess) { NSString *message = [NSString stringWithFormat:@"Set session attribute - %@:%@", key, value]; - [MPLog debugWithMessage:message]; + [logger debug:message]; } else { NSString *message = [NSString stringWithFormat:@"Could not set session attribute - %@:%@\n Reason: %@", key, value, [MPBackendController_PRIVATE execStatusDescription:execStatus]]; - [MPLog errorWithMessage:message]; + [logger error:message]; } }]; } @@ -1525,10 +1533,10 @@ - (void)upload { MPExecStatus execStatus = [strongSelf.backendController waitForKitsAndUploadWithCompletionHandler:nil]; if (execStatus == MPExecStatusSuccess) { - [MPLog debugWithMessage:@"Forcing Upload"]; + [logger debug:@"Forcing Upload"]; } else { NSString *message = [NSString stringWithFormat:@"Could not upload data: %@", [MPBackendController_PRIVATE execStatusDescription:execStatus]]; - [MPLog errorWithMessage:message]; + [logger error:message]; } }]; } @@ -1633,7 +1641,7 @@ - (void)initializeWKWebView:(WKWebView *)webView bridgeName:(NSString *)bridgeNa NSString *bridgeValue = [self webviewBridgeValueWithCustomerBridgeName:bridgeName]; if (bridgeValue == nil) { - [MPLog errorWithMessage:@"Unable to initialize webview due to missing or invalid bridgeName"]; + [logger error:@"Unable to initialize webview due to missing or invalid bridgeName"]; return; } NSString *bridgeVersion = [self bridgeVersion]; @@ -1653,14 +1661,14 @@ - (void)userContentController:(nonnull WKUserContentController *)userContentCont NSString *body = message.body; if (body == nil || ![body isKindOfClass:[NSString class]]) { - [MPLog errorWithMessage:@"Unexpected non-string body received from webview bridge"]; + [logger error:@"Unexpected non-string body received from webview bridge"]; return; } @try { NSData *bodyData = [body dataUsingEncoding:NSUTF8StringEncoding]; if (bodyData == nil) { - [MPLog errorWithMessage:@"Unable to create data from webview bridge body string"]; + [logger error:@"Unable to create data from webview bridge body string"]; return; } @@ -1668,28 +1676,28 @@ - (void)userContentController:(nonnull WKUserContentController *)userContentCont NSDictionary *bodyDictionary = [NSJSONSerialization JSONObjectWithData:bodyData options:kNilOptions error:&error]; if (error != nil || bodyDictionary == nil || ![bodyDictionary isKindOfClass:[NSDictionary class]]) { NSString *message = [NSString stringWithFormat:@"Unable to create dictionary from webview data. error=%@", error]; - [MPLog errorWithMessage:message]; + [logger error:message]; return; } NSString *kPathKey = @"path"; NSString *path = bodyDictionary[kPathKey]; if (path == nil || ![path isKindOfClass:[NSString class]]) { - [MPLog errorWithMessage:@"Unable to retrieve path from webview dictionary"]; + [logger error:@"Unable to retrieve path from webview dictionary"]; return; } NSString *kValueKey = @"value"; NSDictionary *value = bodyDictionary[kValueKey]; if (value == nil || ![value isKindOfClass:[NSDictionary class]]) { - [MPLog errorWithMessage:@"Unable to retrieve value from webview dictionary"]; + [logger error:@"Unable to retrieve value from webview dictionary"]; return; } [self handleWebviewCommand:path dictionary:value]; } @catch (NSException *e) { NSString *message = [NSString stringWithFormat:@"Exception processing WKWebView event: %@", e.reason]; - [MPLog errorWithMessage:message]; + [logger error:message]; } } @@ -1697,14 +1705,14 @@ - (void)handleWebviewCommand:(NSString *)command dictionary:(NSDictionary *)dict [self.listenerController onAPICalled:_cmd parameter1:command parameter2:dictionary]; if (!command || ![command isKindOfClass:[NSString class]] || (dictionary && ![dictionary isKindOfClass:[NSDictionary class]])) { - [MPLog errorWithMessage:@"Unexpected data received from embedded webview"]; + [logger error:@"Unexpected data received from embedded webview"]; return; } if ([command hasPrefix:kMParticleWebViewPathLogEvent]) { NSNumber *eventDataType = dictionary[@"EventDataType"]; if (eventDataType == nil || ![eventDataType isKindOfClass:[NSNumber class]]) { - [MPLog errorWithMessage:@"Unexpected event data type received from embedded webview"]; + [logger error:@"Unexpected event data type received from embedded webview"]; return; } MPJavascriptMessageType messageType = (MPJavascriptMessageType)[eventDataType integerValue]; @@ -1777,7 +1785,7 @@ - (void)handleWebviewCommand:(NSString *)command dictionary:(NSDictionary *)dict if (!request) { NSString *message = [NSString stringWithFormat:@"Unable to create identify request from webview JS dictionary: %@", dictionary]; - [MPLog errorWithMessage:message]; + [logger error:message]; return; } @@ -1791,7 +1799,7 @@ - (void)handleWebviewCommand:(NSString *)command dictionary:(NSDictionary *)dict if (!request) { NSString *message = [NSString stringWithFormat:@"Unable to create login request from webview JS dictionary: %@", dictionary]; - [MPLog errorWithMessage:message]; + [logger error:message]; return; } @@ -1803,7 +1811,7 @@ - (void)handleWebviewCommand:(NSString *)command dictionary:(NSDictionary *)dict if (!request) { NSString *message = [NSString stringWithFormat:@"Unable to create logout request from webview JS dictionary: %@", dictionary]; - [MPLog errorWithMessage:message]; + [logger error:message]; return; } @@ -1815,7 +1823,7 @@ - (void)handleWebviewCommand:(NSString *)command dictionary:(NSDictionary *)dict if (!request) { NSString *message = [NSString stringWithFormat:@"Unable to create modify request from webview JS dictionary: %@", dictionary]; - [MPLog errorWithMessage:message]; + [logger error:message]; return; } @@ -1832,7 +1840,7 @@ - (void)handleWebviewCommand:(NSString *)command dictionary:(NSDictionary *)dict } } else if ([command hasPrefix:kMParticleWebViewPathSetUserAttribute]) { if (!dictionary[@"key"] || (NSNull *)dictionary[@"key"] == [NSNull null]) { - [MPLog errorWithMessage:@"Unexpected user attribute data received from webview"]; + [logger error:@"Unexpected user attribute data received from webview"]; return; } if (!dictionary[@"value"]) { @@ -1846,7 +1854,7 @@ - (void)handleWebviewCommand:(NSString *)command dictionary:(NSDictionary *)dict } } else if ([command hasPrefix:kMParticleWebViewPathSetSessionAttribute]) { if (!dictionary[@"key"]) { - [MPLog errorWithMessage:@"Unexpected session attribute data received from webview"]; + [logger error:@"Unexpected session attribute data received from webview"]; return; } if ((NSNull *)dictionary[@"key"] != [NSNull null] && (NSNull *)dictionary[@"value"] != [NSNull null]) {