diff --git a/Sources/EmbraceCore/Internal/Embrace+Setup.swift b/Sources/EmbraceCore/Internal/Embrace+Setup.swift index 75fe0bb0..06d52c29 100644 --- a/Sources/EmbraceCore/Internal/Embrace+Setup.swift +++ b/Sources/EmbraceCore/Internal/Embrace+Setup.swift @@ -7,6 +7,7 @@ import EmbraceCommon import EmbraceOTel import EmbraceStorage import EmbraceUpload +import EmbraceObjCUtils extension Embrace { static func createStorage(options: Embrace.Options) throws -> EmbraceStorage { @@ -27,7 +28,9 @@ extension Embrace { static func createUpload(options: Embrace.Options, deviceId: String) -> EmbraceUpload? { // endpoints - guard let sessionsURL = URL.sessionsEndpoint(basePath: options.endpoints.baseURL), + guard let sessionsURL = EMBDevice.isDebuggerAttached ? + URL.sessionsEndpoint(basePath: options.endpoints.developmentBaseURL) : + URL.sessionsEndpoint(basePath: options.endpoints.baseURL), let blobsURL = URL.blobsEndpoint(basePath: options.endpoints.baseURL) else { ConsoleLog.error("Failed to initialize endpoints!") return nil diff --git a/Sources/EmbraceObjCUtils/include/EMBDevice.h b/Sources/EmbraceObjCUtils/include/EMBDevice.h index d401d799..47344c4b 100644 --- a/Sources/EmbraceObjCUtils/include/EMBDevice.h +++ b/Sources/EmbraceObjCUtils/include/EMBDevice.h @@ -5,32 +5,31 @@ NS_ASSUME_NONNULL_BEGIN -extern bool IsDebuggerAttached(void); - @interface EMBDevice : NSObject --(instancetype)init NS_UNAVAILABLE; +- (instancetype)init NS_UNAVAILABLE; -@property (class, nullable, readonly) NSString * appVersion; -@property (class, nullable, readonly) NSString * buildUUID; -@property (class, nullable, readonly) NSString * screenResolution; +@property (class, nullable, readonly) NSString *appVersion; +@property (class, nullable, readonly) NSString *buildUUID; +@property (class, nullable, readonly) NSString *screenResolution; -@property (class, readonly) NSString * environment; -@property (class, readonly) NSString * environmentDetail; -@property (class, readonly) NSString * bundleVersion; -@property (class, readonly) NSString * manufacturer; -@property (class, readonly) NSString * model; -@property (class, readonly) NSString * architecture; -@property (class, readonly) NSString * locale; +@property (class, readonly) NSString *environment; +@property (class, readonly) NSString *environmentDetail; +@property (class, readonly) NSString *bundleVersion; +@property (class, readonly) NSString *manufacturer; +@property (class, readonly) NSString *model; +@property (class, readonly) NSString *architecture; +@property (class, readonly) NSString *locale; -@property (class, readonly) NSString * operatingSystemType; -@property (class, readonly) NSString * operatingSystemVersion; -@property (class, readonly) NSString * operatingSystemBuild; -@property (class, readonly) NSString * timezoneDescription; +@property (class, readonly) NSString *operatingSystemType; +@property (class, readonly) NSString *operatingSystemVersion; +@property (class, readonly) NSString *operatingSystemBuild; +@property (class, readonly) NSString *timezoneDescription; -@property (class, readonly) NSNumber * totalDiskSpace; +@property (class, readonly) NSNumber *totalDiskSpace; @property (class, readonly) BOOL isJailbroken; +@property (class, readonly) BOOL isDebuggerAttached; @end diff --git a/Sources/EmbraceObjCUtils/source/EMBDevice.m b/Sources/EmbraceObjCUtils/source/EMBDevice.m index 5d90013e..dff7c05a 100644 --- a/Sources/EmbraceObjCUtils/source/EMBDevice.m +++ b/Sources/EmbraceObjCUtils/source/EMBDevice.m @@ -56,40 +56,6 @@ typedef NS_ENUM(NSInteger, EMBReleaseMode) { EMBReleaseAppStore }; -// see: https://developer.apple.com/library/content/qa/qa1361/_index.html -bool IsDebuggerAttached(void) -// Returns true if the current process is being debugged (either -// running under the debugger or has a debugger attached post facto). -{ - int junk; - int mib[4]; - struct kinfo_proc info; - size_t size; - - // Initialize the flags so that, if sysctl fails for some bizarre - // reason, we get a predictable result. - - info.kp_proc.p_flag = 0; - - // Initialize mib, which tells sysctl the info we want, in this case - // we're looking for information about a specific process ID. - - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_PID; - mib[3] = getpid(); - - // Call sysctl. - - size = sizeof(info); - junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0); - assert(junk == 0); - - // We're being debugged if the P_TRACED flag is set. - - return ( (info.kp_proc.p_flag & P_TRACED) != 0 ); -} - @implementation EMBDevice #pragma mark - Accessors @@ -484,4 +450,38 @@ + (EMBReleaseMode)getReleaseMode #endif } +// see: https://developer.apple.com/library/content/qa/qa1361/_index.html +// Returns true if the current process is being debugged (either +// running under the debugger or has a debugger attached post facto). ++ (BOOL)isDebuggerAttached +{ + int junk; + int mib[4]; + struct kinfo_proc info; + size_t size; + + // Initialize the flags so that, if sysctl fails for some bizarre + // reason, we get a predictable result. + + info.kp_proc.p_flag = 0; + + // Initialize mib, which tells sysctl the info we want, in this case + // we're looking for information about a specific process ID. + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PID; + mib[3] = getpid(); + + // Call sysctl. + + size = sizeof(info); + junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0); + assert(junk == 0); + + // We're being debugged if the P_TRACED flag is set. + + return ( (info.kp_proc.p_flag & P_TRACED) != 0 ); +} + @end