diff --git a/Example/Example/AppDelegate.swift b/Example/Example/AppDelegate.swift index 1cc7e2847..429f9a26b 100644 --- a/Example/Example/AppDelegate.swift +++ b/Example/Example/AppDelegate.swift @@ -34,7 +34,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIWindowSceneDelegate, UN Radar.setMetadata([ "foo": "bar" ]) Radar.setDelegate(self) Radar.setVerifiedDelegate(self) - + + return true } diff --git a/RadarSDK.xcodeproj/project.pbxproj b/RadarSDK.xcodeproj/project.pbxproj index dfc5f4ba4..449db2dfe 100644 --- a/RadarSDK.xcodeproj/project.pbxproj +++ b/RadarSDK.xcodeproj/project.pbxproj @@ -169,6 +169,8 @@ F65AF72C2C10B242002BA009 /* get_config_response.json in Resources */ = {isa = PBXBuildFile; fileRef = F65AF72B2C10B242002BA009 /* get_config_response.json */; }; F662C8B42CA1BF86001B24EC /* RadarLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = F662C8B32CA1BF86001B24EC /* RadarLog.swift */; }; F662C8B62CA1C96C001B24EC /* RadarUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = F662C8B52CA1C96C001B24EC /* RadarUtils.swift */; }; + F662C9012CA3144B001B24EC /* RadarUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = F662C9002CA3144B001B24EC /* RadarUtils.h */; }; + F662C9022CA3144B001B24EC /* RadarLog.h in Headers */ = {isa = PBXBuildFile; fileRef = F662C8FF2CA3144B001B24EC /* RadarLog.h */; }; F667F8272BFBF3C8001F2F67 /* RadarSdkConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = F667F8262BFBF3C8001F2F67 /* RadarSdkConfiguration.m */; }; F667F8292BFBF3D1001F2F67 /* RadarSdkConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = F667F8282BFBF3D1001F2F67 /* RadarSdkConfiguration.h */; }; F6F959802C3D7D9900BC30FE /* RadarTimeZone.h in Headers */ = {isa = PBXBuildFile; fileRef = F6F9597F2C3D7D9900BC30FE /* RadarTimeZone.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -340,6 +342,8 @@ F65AF72B2C10B242002BA009 /* get_config_response.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = get_config_response.json; sourceTree = ""; }; F662C8B32CA1BF86001B24EC /* RadarLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadarLog.swift; sourceTree = ""; }; F662C8B52CA1C96C001B24EC /* RadarUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadarUtils.swift; sourceTree = ""; }; + F662C8FF2CA3144B001B24EC /* RadarLog.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RadarLog.h; sourceTree = ""; }; + F662C9002CA3144B001B24EC /* RadarUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RadarUtils.h; sourceTree = ""; }; F667F8262BFBF3C8001F2F67 /* RadarSdkConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RadarSdkConfiguration.m; sourceTree = ""; }; F667F8282BFBF3D1001F2F67 /* RadarSdkConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RadarSdkConfiguration.h; sourceTree = ""; }; F6F9597F2C3D7D9900BC30FE /* RadarTimeZone.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RadarTimeZone.h; sourceTree = ""; }; @@ -489,6 +493,7 @@ DD4C104925D87E3E009C2E36 /* RadarDelegateHolder.m */, DD236CF723088F8400EB88F9 /* RadarLocationManager.h */, DD236CF823088F8400EB88F9 /* RadarLocationManager.m */, + F662C8FF2CA3144B001B24EC /* RadarLog.h */, F662C8B32CA1BF86001B24EC /* RadarLog.swift */, 96A5A11627ADA02E007B960B /* RadarLogBuffer.h */, DD236D66230A0D6700EB88F9 /* RadarLogger.h */, @@ -512,6 +517,7 @@ DD236D0F2309B3FE00EB88F9 /* RadarState.m */, DD236CEB2308821600EB88F9 /* RadarTrackingOptions.m */, DD8CCDF7246872360011690D /* RadarTripOptions.m */, + F662C9002CA3144B001B24EC /* RadarUtils.h */, F662C8B52CA1C96C001B24EC /* RadarUtils.swift */, 82F7FAEC2A65FE030055AA4B /* RadarVerificationManager.h */, 82F7FAED2A65FE030055AA4B /* RadarVerificationManager.m */, @@ -622,6 +628,8 @@ 96A5A0D627AD9F41007B960B /* RadarRouteMatrix+Internal.h in Headers */, 96A5A0FA27AD9F7F007B960B /* RadarRouteMatrix.h in Headers */, 96A5A0CC27AD9F41007B960B /* RadarUser+Internal.h in Headers */, + F662C9012CA3144B001B24EC /* RadarUtils.h in Headers */, + F662C9022CA3144B001B24EC /* RadarLog.h in Headers */, 96A5A10327AD9F7F007B960B /* RadarGeofence.h in Headers */, 0107AA222622005B008AB52F /* RadarState.h in Headers */, 96A5A11A27ADA02F007B960B /* RadarLogBuffer.h in Headers */, diff --git a/RadarSDK/Radar.m b/RadarSDK/Radar.m index b9de2aebf..7c6da1b59 100644 --- a/RadarSDK/Radar.m +++ b/RadarSDK/Radar.m @@ -23,6 +23,7 @@ #import "RadarNotificationHelper.h" #import "RadarSDK/RadarSDK-Swift.h" +#import "RadarLog.h" @interface Radar () diff --git a/RadarSDK/RadarAPIClient.m b/RadarSDK/RadarAPIClient.m index 4523b1a0d..584e4452f 100644 --- a/RadarSDK/RadarAPIClient.m +++ b/RadarSDK/RadarAPIClient.m @@ -35,7 +35,7 @@ #import "RadarVerifiedLocationToken+Internal.h" #import -#import "RadarSDK/RadarSDK-Swift.h" +#import "RadarLog.h" @implementation RadarAPIClient diff --git a/RadarSDK/RadarLog.h b/RadarSDK/RadarLog.h new file mode 100644 index 000000000..b2e21175e --- /dev/null +++ b/RadarSDK/RadarLog.h @@ -0,0 +1,59 @@ +// +// RadarLog.h +// RadarSDK +// +// Copyright © 2021 Radar Labs, Inc. All rights reserved. +// + +#import "Radar.h" + +/** + Represents a debug log. + */ +@interface RadarLog : NSObject + +/** + The levels for debug logs. + */ +@property (assign, nonatomic, readonly) RadarLogLevel level; + +/** + The log message. + */ +@property (nonnull, copy, nonatomic, readonly) NSString *message; + +/** + The log type. + */ +@property (assign, nonatomic, readonly) RadarLogType type; + +/** + The datetime when the log occurred on the device. + */ +@property (nonnull, copy, nonatomic, readonly) NSDate *createdAt; + +- (instancetype _Nullable)initWithLevel:(RadarLogLevel)level type:(RadarLogType)type message:(NSString *_Nullable)message; + +- (NSDictionary *_Nonnull)dictionaryValue; + ++ (NSArray *_Nullable)arrayForLogs:(NSArray *_Nullable)logs NS_SWIFT_NAME(arrayForLogs(_:)); + +/** + Returns a display string for a log level. + + @param level A log level + + @return A display string for the log level. + */ ++ (NSString *_Nonnull)stringForLogLevel:(RadarLogLevel)level NS_SWIFT_NAME(stringForLogLevel(_:)); + +/** + Return the log level for a specific display string + + @param string A display string for the log level + + @return A log level. +*/ ++ (RadarLogLevel) levelFromString:(NSString *_Nonnull) string; + +@end diff --git a/RadarSDK/RadarLog.swift b/RadarSDK/RadarLog.swift index b6702bbbd..acebbec42 100644 --- a/RadarSDK/RadarLog.swift +++ b/RadarSDK/RadarLog.swift @@ -9,7 +9,24 @@ import Foundation -@objc public class RadarLog: NSObject { +@objc(RadarLog) +class RadarLog: NSObject, NSCoding { + public func encode(with coder: NSCoder) { + coder.encode(level, forKey: "level") + coder.encode(message, forKey: "message") + coder.encode(type.rawValue, forKey: "type") + coder.encode(createdAt, forKey: "createdAt") + } + + public required convenience init?(coder: NSCoder) { + let level = coder.decodeObject(forKey: "level") as! RadarLogLevel + let type = RadarLogType(rawValue: coder.decodeObject(forKey: "type") as! Int)! + let message = coder.decodeObject(forKey: "message") as! NSString + let createdAt = coder.decodeObject(forKey: "createdAt") as! NSDate + + self.init(level: level, type: type, message: message) + } + /** The levels for debug logs. */ @@ -30,11 +47,11 @@ import Foundation */ @objc public let createdAt: NSDate; - @objc public init(level: RadarLogLevel, type: RadarLogType, message: NSString, createdAt: NSDate) { + @objc public init(level: RadarLogLevel, type: RadarLogType, message: NSString) { self.level = level self.message = message self.type = type - self.createdAt = createdAt + self.createdAt = NSDate() } @objc public func dictionaryValue() -> Dictionary { @@ -135,5 +152,12 @@ import Foundation return RadarLogLevel.info; } } +// +// @objc public func encode(withCoder coder: NSCoder){ +// coder.encode(level.rawValue, forKey: "level") +// coder.encode(message, forKey: "message") +// coder.encode(type.rawValue, forKey: "type") +// coder.encode(createdAt, forKey: "createdAt") +// } } diff --git a/RadarSDK/RadarLogBuffer.m b/RadarSDK/RadarLogBuffer.m index 29dee5b2c..dc1b36c14 100644 --- a/RadarSDK/RadarLogBuffer.m +++ b/RadarSDK/RadarLogBuffer.m @@ -6,7 +6,7 @@ // #import "RadarLogBuffer.h" -#import "RadarSDK/RadarSDK-Swift.h" +#import "RadarLog.h" #import "RadarFileStorage.h" #import "RadarSettings.h" @@ -60,7 +60,7 @@ - (void)write:(RadarLogLevel)level type:(RadarLogType)type message:(NSString *)m } - (void)write:(RadarLogLevel)level type:(RadarLogType)type message:(NSString *)message forcePersist:(BOOL)forcePersist { - RadarLog *radarLog = [[RadarLog alloc] initWithLevel:level type:type message:message createdAt:[NSDate new]]; + RadarLog *radarLog = [[RadarLog alloc] initWithLevel:level type:type message:message]; // bypass sync lock here to ensure that other writes or persisting logs don't block the current thread as the app is terminating if (forcePersist && (_persistentLogFeatureFlag || [[NSProcessInfo processInfo] environment][@"XCTestConfigurationFilePath"])) { @@ -159,14 +159,14 @@ - (void)purgeOldestLogs { dirSize = [[self getLogFilesInTimeOrder] count]; if (!printedPurgedLogs) { printedPurgedLogs = YES; - RadarLog *purgeLog = [[RadarLog alloc] initWithLevel:RadarLogLevelDebug type:RadarLogTypeNone message:kPurgedLogLine createdAt:[NSDate new]]; + RadarLog *purgeLog = [[RadarLog alloc] initWithLevel:RadarLogLevelDebug type:RadarLogTypeNone message:kPurgedLogLine]; [self writeToFileStorage:@[purgeLog]]; } } } else { // drop the oldest N logs from the buffer [logBuffer removeObjectsInRange:NSMakeRange(0, PURGE_AMOUNT)]; - RadarLog *purgeLog = [[RadarLog alloc] initWithLevel:RadarLogLevelDebug type:RadarLogTypeNone message:kPurgedLogLine createdAt:[NSDate new]]; + RadarLog *purgeLog = [[RadarLog alloc] initWithLevel:RadarLogLevelDebug type:RadarLogTypeNone message:kPurgedLogLine]; [logBuffer insertObject:purgeLog atIndex:0]; } } diff --git a/RadarSDK/RadarReplayBuffer.m b/RadarSDK/RadarReplayBuffer.m index 542cd1fb7..3f550ccb2 100644 --- a/RadarSDK/RadarReplayBuffer.m +++ b/RadarSDK/RadarReplayBuffer.m @@ -73,6 +73,7 @@ - (void)writeNewReplayToBuffer:(NSMutableDictionary *)replayParams { return flushableReplays; } +// function name? - (void)flushReplaysWithCompletionHandler:(NSDictionary *_Nullable)replayParams completionHandler:(RadarFlushReplaysCompletionHandler _Nullable)completionHandler { if (isFlushing) { diff --git a/RadarSDK/RadarSdkConfiguration.m b/RadarSDK/RadarSdkConfiguration.m index 074eb45c7..56a94c360 100644 --- a/RadarSDK/RadarSdkConfiguration.m +++ b/RadarSDK/RadarSdkConfiguration.m @@ -10,7 +10,7 @@ #import "RadarAPIClient.h" #import "RadarSettings.h" -#import "RadarSDK/RadarSDK-Swift.h" +#import "RadarLog.h" @implementation RadarSdkConfiguration diff --git a/RadarSDK/RadarUtils.h b/RadarSDK/RadarUtils.h new file mode 100644 index 000000000..db38af04e --- /dev/null +++ b/RadarSDK/RadarUtils.h @@ -0,0 +1,39 @@ +// +// RadarUtils.h +// RadarSDK +// +// Copyright © 2019 Radar Labs, Inc. All rights reserved. +// + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface RadarUtils : NSObject + +@property (class, nonatomic, assign, readonly) NSDateFormatter *isoDateFormatter; + ++ (NSString *)deviceModel; ++ (NSString *)deviceOS; ++ (NSString *)country; ++ (NSNumber *)timeZoneOffset; ++ (NSString *)sdkVersion; ++ (NSString *)deviceId; ++ (NSString *)deviceType; ++ (NSString *)deviceMake; ++ (BOOL)isSimulator; ++ (BOOL)locationBackgroundMode; ++ (NSString *)locationAuthorization; ++ (NSString *)locationAccuracyAuthorization; ++ (BOOL)foreground; ++ (NSTimeInterval)backgroundTimeRemaining; ++ (CLLocation *)locationForDictionary:(NSDictionary *_Nonnull)dict; ++ (NSDictionary *)dictionaryForLocation:(CLLocation *)location; ++ (NSString *)dictionaryToJson:(NSDictionary *)dict; ++ (NSDictionary *)extractGeofenceIdAndTimestampFromIdentifier:(NSString *)identifier; ++ (void)runOnMainThread:(dispatch_block_t)block; + +@end + +NS_ASSUME_NONNULL_END diff --git a/RadarSDKTests/RadarSDKTests.m b/RadarSDKTests/RadarSDKTests.m index 298cded5e..25cf88d7a 100644 --- a/RadarSDKTests/RadarSDKTests.m +++ b/RadarSDKTests/RadarSDKTests.m @@ -822,7 +822,7 @@ - (void)test_Radar_getContext_errorLocation { [expectation fulfill]; }]; - + [self waitForExpectationsWithTimeout:60 handler:^(NSError *_Nullable error) { if (error) {