diff --git a/mParticle-Apple-SDK.xcodeproj/project.pbxproj b/mParticle-Apple-SDK.xcodeproj/project.pbxproj index 64193309..af4b524c 100644 --- a/mParticle-Apple-SDK.xcodeproj/project.pbxproj +++ b/mParticle-Apple-SDK.xcodeproj/project.pbxproj @@ -96,8 +96,6 @@ 53A79B6F29CDFB2000E7489F /* MPIdentityApi.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79AA129CDFB1E00E7489F /* MPIdentityApi.m */; }; 53A79B7029CDFB2000E7489F /* MPIdentityApiManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79AA229CDFB1E00E7489F /* MPIdentityApiManager.m */; }; 53A79B7129CDFB2000E7489F /* MPBackendController.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79AA329CDFB1E00E7489F /* MPBackendController.h */; }; - 53A79B7229CDFB2000E7489F /* MPLocationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79AA529CDFB1E00E7489F /* MPLocationManager.h */; }; - 53A79B7329CDFB2000E7489F /* MPLocationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79AA629CDFB1E00E7489F /* MPLocationManager.m */; }; 53A79B7429CDFB2000E7489F /* MPURLRequestBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79AA829CDFB1E00E7489F /* MPURLRequestBuilder.h */; }; 53A79B7529CDFB2000E7489F /* MPNetworkCommunication.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79AA929CDFB1E00E7489F /* MPNetworkCommunication.m */; }; 53A79B7629CDFB2000E7489F /* MPURL.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79AAA29CDFB1E00E7489F /* MPURL.m */; }; @@ -395,7 +393,6 @@ 53A79D4129CE23F700E7489F /* MPDatabaseMigrationController.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79ABA29CDFB1E00E7489F /* MPDatabaseMigrationController.h */; }; 53A79D4229CE23F700E7489F /* MPZip.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B1B29CDFB1F00E7489F /* MPZip.h */; }; 53A79D4329CE23F700E7489F /* MParticleUserNotification.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79ABD29CDFB1E00E7489F /* MParticleUserNotification.h */; }; - 53A79D4429CE23F700E7489F /* MPLocationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79AA529CDFB1E00E7489F /* MPLocationManager.h */; }; 53A79D4529CE23F700E7489F /* MPForwardQueueItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B5229CDFB1F00E7489F /* MPForwardQueueItem.h */; }; 53A79D4629CE23F700E7489F /* MPDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2B29CDFB1F00E7489F /* MPDevice.h */; }; 53A79D4729CE23F700E7489F /* MPAttributeProjection.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B4E29CDFB1F00E7489F /* MPAttributeProjection.h */; }; @@ -510,9 +507,10 @@ 53A79DB929CE23F700E7489F /* MPKitContainer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B5029CDFB1F00E7489F /* MPKitContainer.mm */; }; 53A79DBA29CE23F700E7489F /* MPUploadBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1229CDFB1F00E7489F /* MPUploadBuilder.m */; }; 53A79DBC29CE23F700E7489F /* MPBaseProjection.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B5329CDFB1F00E7489F /* MPBaseProjection.m */; }; - 53A79DBD29CE23F700E7489F /* MPLocationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79AA629CDFB1E00E7489F /* MPLocationManager.m */; }; 53A79DBE29CE23F700E7489F /* MPUserAttributeChange.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B2729CDFB1F00E7489F /* MPUserAttributeChange.m */; }; 53A79DBF29CE23F700E7489F /* MPIdentityApiManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79AA229CDFB1E00E7489F /* MPIdentityApiManager.m */; }; + 53B28FB22C938C26009072FC /* MPLocationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53B28FB12C938C26009072FC /* MPLocationManager.swift */; }; + 53B28FB32C938C26009072FC /* MPLocationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53B28FB12C938C26009072FC /* MPLocationManager.swift */; }; 53B33E8A2A4606CD00CC8A19 /* MPSideloadedKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53B33E892A4606CD00CC8A19 /* MPSideloadedKit.swift */; }; 53B33E8B2A4606CD00CC8A19 /* MPSideloadedKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53B33E892A4606CD00CC8A19 /* MPSideloadedKit.swift */; }; 53FDD1BD2AE871AF003D5FA1 /* MPIHasher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53FDD1BC2AE871AF003D5FA1 /* MPIHasher.swift */; }; @@ -558,8 +556,6 @@ 53A79AA129CDFB1E00E7489F /* MPIdentityApi.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPIdentityApi.m; sourceTree = ""; }; 53A79AA229CDFB1E00E7489F /* MPIdentityApiManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPIdentityApiManager.m; sourceTree = ""; }; 53A79AA329CDFB1E00E7489F /* MPBackendController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPBackendController.h; sourceTree = ""; }; - 53A79AA529CDFB1E00E7489F /* MPLocationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPLocationManager.h; sourceTree = ""; }; - 53A79AA629CDFB1E00E7489F /* MPLocationManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPLocationManager.m; sourceTree = ""; }; 53A79AA829CDFB1E00E7489F /* MPURLRequestBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPURLRequestBuilder.h; sourceTree = ""; }; 53A79AA929CDFB1E00E7489F /* MPNetworkCommunication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPNetworkCommunication.m; sourceTree = ""; }; 53A79AAA29CDFB1E00E7489F /* MPURL.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPURL.m; sourceTree = ""; }; @@ -807,6 +803,7 @@ 53A79CFE29CE12AB00E7489F /* mParticle-Apple-SDK.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; name = "mParticle-Apple-SDK.modulemap"; path = "Framework/mParticle-Apple-SDK.modulemap"; sourceTree = ""; }; 53A79CFF29CE23D600E7489F /* mParticle-Apple-SDK-NoLocation.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; name = "mParticle-Apple-SDK-NoLocation.modulemap"; path = "Framework/mParticle-Apple-SDK-NoLocation.modulemap"; sourceTree = ""; }; 53A79DC629CE23F700E7489F /* mParticle_Apple_SDK_NoLocation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = mParticle_Apple_SDK_NoLocation.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 53B28FB12C938C26009072FC /* MPLocationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPLocationManager.swift; sourceTree = ""; }; 53B33E892A4606CD00CC8A19 /* MPSideloadedKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPSideloadedKit.swift; sourceTree = ""; }; 53FDD1BC2AE871AF003D5FA1 /* MPIHasher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPIHasher.swift; sourceTree = ""; }; D3724C182AE02AF60074CD67 /* mParticle_Apple_SDK_NoLocation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mParticle_Apple_SDK_NoLocation.h; sourceTree = ""; }; @@ -928,8 +925,7 @@ 53A79AA429CDFB1E00E7489F /* Location */ = { isa = PBXGroup; children = ( - 53A79AA529CDFB1E00E7489F /* MPLocationManager.h */, - 53A79AA629CDFB1E00E7489F /* MPLocationManager.m */, + 53B28FB12C938C26009072FC /* MPLocationManager.swift */, ); path = Location; sourceTree = ""; @@ -1395,7 +1391,6 @@ 53A79B8529CDFB2000E7489F /* MPDatabaseMigrationController.h in Headers */, 53A79BE029CDFB2000E7489F /* MPZip.h in Headers */, 53A79B8729CDFB2000E7489F /* MParticleUserNotification.h in Headers */, - 53A79B7229CDFB2000E7489F /* MPLocationManager.h in Headers */, 53A79C1029CDFB2100E7489F /* MPForwardQueueItem.h in Headers */, 53A79BF029CDFB2000E7489F /* MPDevice.h in Headers */, 53A79C0C29CDFB2100E7489F /* MPAttributeProjection.h in Headers */, @@ -1502,7 +1497,6 @@ 53A79D4129CE23F700E7489F /* MPDatabaseMigrationController.h in Headers */, 53A79D4229CE23F700E7489F /* MPZip.h in Headers */, 53A79D4329CE23F700E7489F /* MParticleUserNotification.h in Headers */, - 53A79D4429CE23F700E7489F /* MPLocationManager.h in Headers */, 53A79D4529CE23F700E7489F /* MPForwardQueueItem.h in Headers */, 53A79D4629CE23F700E7489F /* MPDevice.h in Headers */, 53A79D4729CE23F700E7489F /* MPAttributeProjection.h in Headers */, @@ -1818,6 +1812,7 @@ 53A79B9729CDFB2000E7489F /* MPIntegrationAttributes.m in Sources */, 53A79B6A29CDFB2000E7489F /* MPAliasRequest.m in Sources */, 53A79B6829CDFB2000E7489F /* MParticleUser.m in Sources */, + 53B28FB22C938C26009072FC /* MPLocationManager.swift in Sources */, 53A79BE529CDFB2000E7489F /* MPResponseConfig.m in Sources */, 53A79BC529CDFB2000E7489F /* MParticleReachability.m in Sources */, 53A79C0B29CDFB2100E7489F /* MPKitExecStatus.m in Sources */, @@ -1849,7 +1844,6 @@ 53A79C0E29CDFB2100E7489F /* MPKitContainer.mm in Sources */, 53A79BD729CDFB2000E7489F /* MPUploadBuilder.m in Sources */, 53A79C1129CDFB2100E7489F /* MPBaseProjection.m in Sources */, - 53A79B7329CDFB2000E7489F /* MPLocationManager.m in Sources */, 53A79BEC29CDFB2000E7489F /* MPUserAttributeChange.m in Sources */, 53A79B7029CDFB2000E7489F /* MPIdentityApiManager.m in Sources */, ); @@ -1983,6 +1977,7 @@ 53A79D9B29CE23F700E7489F /* MPIntegrationAttributes.m in Sources */, 53A79D9C29CE23F700E7489F /* MPAliasRequest.m in Sources */, 53A79D9D29CE23F700E7489F /* MParticleUser.m in Sources */, + 53B28FB32C938C26009072FC /* MPLocationManager.swift in Sources */, 53A79D9E29CE23F700E7489F /* MPResponseConfig.m in Sources */, 53A79D9F29CE23F700E7489F /* MParticleReachability.m in Sources */, 53A79DA029CE23F700E7489F /* MPKitExecStatus.m in Sources */, @@ -2014,7 +2009,6 @@ 53A79DB929CE23F700E7489F /* MPKitContainer.mm in Sources */, 53A79DBA29CE23F700E7489F /* MPUploadBuilder.m in Sources */, 53A79DBC29CE23F700E7489F /* MPBaseProjection.m in Sources */, - 53A79DBD29CE23F700E7489F /* MPLocationManager.m in Sources */, 53A79DBE29CE23F700E7489F /* MPUserAttributeChange.m in Sources */, 53A79DBF29CE23F700E7489F /* MPIdentityApiManager.m in Sources */, ); diff --git a/mParticle-Apple-SDK/Location/MPLocationManager.h b/mParticle-Apple-SDK/Location/MPLocationManager.h deleted file mode 100644 index 342f4115..00000000 --- a/mParticle-Apple-SDK/Location/MPLocationManager.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef MPARTICLE_LOCATION_DISABLE -#import -#import "MPEnums.h" - -#if TARGET_OS_IOS == 1 - #import -#endif - -@interface MPLocationManager : NSObject - -#if TARGET_OS_IOS == 1 -@property (nonatomic, strong, nullable) CLLocation *location; -@property (nonatomic, strong, nullable) CLLocationManager *locationManager; -@property (nonatomic, readonly) MPLocationAuthorizationRequest authorizationRequest; -@property (nonatomic, readonly) CLLocationAccuracy requestedAccuracy; -@property (nonatomic, readonly) CLLocationDistance requestedDistanceFilter; -@property (nonatomic) BOOL backgroundLocationTracking; - -- (nullable instancetype)initWithAccuracy:(CLLocationAccuracy)accuracy distanceFilter:(CLLocationDistance)distance authorizationRequest:(MPLocationAuthorizationRequest)authorizationRequest; -- (void)endLocationTracking; -#endif - -+ (BOOL)trackingLocation; - -@end -#endif diff --git a/mParticle-Apple-SDK/Location/MPLocationManager.m b/mParticle-Apple-SDK/Location/MPLocationManager.m deleted file mode 100644 index f2425996..00000000 --- a/mParticle-Apple-SDK/Location/MPLocationManager.m +++ /dev/null @@ -1,112 +0,0 @@ -#ifndef MPARTICLE_LOCATION_DISABLE -#import "MPLocationManager.h" -#import - -static BOOL _trackingLocation = NO; - -#if TARGET_OS_IOS == 1 -@interface MPLocationManager () -@end -#endif - -@implementation MPLocationManager - -#if TARGET_OS_IOS == 1 -- (instancetype)initWithAccuracy:(CLLocationAccuracy)accuracy distanceFilter:(CLLocationDistance)distance authorizationRequest:(MPLocationAuthorizationRequest)authorizationRequest { - self = [super init]; - - CLAuthorizationStatus authorizationStatus = [CLLocationManager authorizationStatus]; - - if (!self || authorizationStatus == kCLAuthorizationStatusRestricted || authorizationStatus == kCLAuthorizationStatusDenied) { - return nil; - } - - self.locationManager.desiredAccuracy = accuracy; - self.locationManager.distanceFilter = distance; - - if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { - NSDictionary *mainBundleInfoDictionary = [[NSBundle mainBundle] infoDictionary]; - - if (authorizationRequest == MPLocationAuthorizationRequestAlways && - [self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)] && - mainBundleInfoDictionary[@"NSLocationAlwaysUsageDescription"]) - { - [self.locationManager requestAlwaysAuthorization]; - } else if (authorizationRequest == MPLocationAuthorizationRequestWhenInUse && - [self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)] && - mainBundleInfoDictionary[@"NSLocationWhenInUseUsageDescription"]) - { - [self.locationManager requestWhenInUseAuthorization]; - } else { - [self.locationManager startUpdatingLocation]; - } - } else { - [self.locationManager startUpdatingLocation]; - } - - _authorizationRequest = authorizationRequest; - _requestedAccuracy = accuracy; - _requestedDistanceFilter = distance; - _trackingLocation = NO; - _backgroundLocationTracking = YES; - - return self; -} - -#pragma mark CLLocationManager Delegate -- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { - _trackingLocation = (status == kCLAuthorizationStatusAuthorizedAlways) || (status == kCLAuthorizationStatusAuthorizedWhenInUse); - - if (_trackingLocation) { - [self.locationManager startUpdatingLocation]; - } -} - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-implementations" -- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { - self.location = newLocation; -} -#pragma clang diagnostic pop - -#pragma mark Public accessors -- (CLLocationManager *)locationManager { - if (_locationManager) { - return _locationManager; - } - - CLAuthorizationStatus authorizationStatus = [CLLocationManager authorizationStatus]; - if (authorizationStatus == kCLAuthorizationStatusRestricted || authorizationStatus == kCLAuthorizationStatusDenied) { - if (_locationManager) { - _locationManager = nil; - _location = nil; - _trackingLocation = NO; - } - - return nil; - } - - [self willChangeValueForKey:@"locationManager"]; - _locationManager = [[CLLocationManager alloc] init]; - _locationManager.delegate = self; - [self didChangeValueForKey:@"locationManager"]; - return _locationManager; -} - -#pragma mark Public methods -- (void)endLocationTracking { - [_locationManager stopUpdatingLocation]; - _locationManager = nil; - - _location = nil; - _trackingLocation = NO; -} -#endif // #if TARGET_OS_IOS == 1 - -#pragma mark Class methods -+ (BOOL)trackingLocation { - return _trackingLocation; -} - -@end -#endif diff --git a/mParticle-Apple-SDK/Location/MPLocationManager.swift b/mParticle-Apple-SDK/Location/MPLocationManager.swift new file mode 100644 index 00000000..8ca2095e --- /dev/null +++ b/mParticle-Apple-SDK/Location/MPLocationManager.swift @@ -0,0 +1,110 @@ +// +// MPLocationManager.swift +// mParticle-Apple-SDK +// +// Created by Ben Baron on 9/12/24. +// + +import Foundation +import UIKit + +#if os(iOS) && !MPARTICLE_LOCATION_DISABLE +import CoreLocation +#endif + +@objc final public class MPLocationManager_PRIVATE: NSObject { + + private static var _trackingLocation = false + @objc public class var trackingLocation: Bool { + return _trackingLocation + } + + #if os(iOS) && !MPARTICLE_LOCATION_DISABLE + private static var _locationManager: CLLocationManager? + + @objc public var location: CLLocation? + @objc public private(set) var authorizationRequest: MPLocationAuthorizationRequest + @objc public private(set) var requestedAccuracy: CLLocationAccuracy + @objc public private(set) var requestedDistanceFilter: CLLocationDistance + @objc public var backgroundLocationTracking: Bool + + @objc public var locationManager: CLLocationManager? { + get { + guard Self._locationManager == nil else { + return Self._locationManager + } + + let authorizationStatus = CLLocationManager.authorizationStatus() + guard authorizationStatus != .restricted && authorizationStatus != .denied else { + if let _ = Self._locationManager { + Self._locationManager = nil + location = nil + Self._trackingLocation = false + } + return nil + } + + let _locationManager = CLLocationManager() + _locationManager.delegate = self + Self._locationManager = _locationManager + return Self._locationManager + } + } + + @objc public init?(accuracy: CLLocationAccuracy, distanceFilter: CLLocationDistance, authorizationRequest: MPLocationAuthorizationRequest) { + let authorizationStatus = CLLocationManager.authorizationStatus() + guard authorizationStatus != .restricted && authorizationStatus != .denied else { + return nil + } + + self.authorizationRequest = authorizationRequest + requestedAccuracy = accuracy + requestedDistanceFilter = distanceFilter + backgroundLocationTracking = true + Self._trackingLocation = false + super.init() + + // Must be run on the main thread or no delegate methods will be called + DispatchQueue.main.async { + if let locationManager = self.locationManager { + locationManager.desiredAccuracy = accuracy + locationManager.distanceFilter = distanceFilter + + let keys = Bundle.main.infoDictionary?.keys + if let keys = keys, authorizationRequest == .always && keys.contains("NSLocationAlwaysUsageDescription") { + locationManager.requestAlwaysAuthorization() + } else if let keys = keys, authorizationRequest == .whenInUse && keys.contains("NSLocationWhenInUseUsageDescription") { + locationManager.requestWhenInUseAuthorization() + } else { + locationManager.startUpdatingLocation() + } + } + } + } + + @objc public func endLocationTracking() { + Self._locationManager?.stopUpdatingLocation() + Self._locationManager = nil + + location = nil + Self._trackingLocation = false + } + + #endif +} + +#if os(iOS) && !MPARTICLE_LOCATION_DISABLE +extension MPLocationManager_PRIVATE: CLLocationManagerDelegate { + public func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { + Self._trackingLocation = (status == .authorizedAlways || status == .authorizedWhenInUse) + + if Self._trackingLocation { + locationManager?.startUpdatingLocation() + } + } + + public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { + location = locations.last + } +} +#endif diff --git a/mParticle-Apple-SDK/MPBackendController.m b/mParticle-Apple-SDK/MPBackendController.m index 03fefa58..141db7bb 100644 --- a/mParticle-Apple-SDK/MPBackendController.m +++ b/mParticle-Apple-SDK/MPBackendController.m @@ -36,12 +36,6 @@ #import "MPIdentityCaching.h" #import "MParticleSwift.h" -#if TARGET_OS_IOS == 1 -#ifndef MPARTICLE_LOCATION_DISABLE -#import "MPLocationManager.h" -#endif -#endif - const NSInteger kNilAttributeValue = 101; const NSInteger kExceededAttributeValueMaximumLength = 104; const NSInteger kExceededAttributeKeyMaximumLength = 105; @@ -1898,7 +1892,7 @@ - (MPExecStatus)beginLocationTrackingWithAccuracy:(CLLocationAccuracy)accuracy d return MPExecStatusDisabledRemotely; } - MPLocationManager *locationManager = [[MPLocationManager alloc] initWithAccuracy:accuracy distanceFilter:distance authorizationRequest:authorizationRequest]; + MPLocationManager_PRIVATE *locationManager = [[MPLocationManager_PRIVATE alloc] initWithAccuracy:accuracy distanceFilter:distance authorizationRequest:authorizationRequest]; [MParticle sharedInstance].stateMachine.locationManager = locationManager ? : nil; return MPExecStatusSuccess; @@ -2137,7 +2131,7 @@ - (void)handleApplicationDidEnterBackground:(NSNotification *)notification { messageInfo:@{kMPAppStateTransitionType: kMPASTBackgroundKey}]; #if TARGET_OS_IOS == 1 #ifndef MPARTICLE_LOCATION_DISABLE - if ([MPLocationManager trackingLocation] && ![MParticle sharedInstance].stateMachine.locationManager.backgroundLocationTracking) { + if ([MPLocationManager_PRIVATE trackingLocation] && ![MParticle sharedInstance].stateMachine.locationManager.backgroundLocationTracking) { [[MParticle sharedInstance].stateMachine.locationManager.locationManager stopUpdatingLocation]; } [messageBuilder location:[MParticle sharedInstance].stateMachine.location]; @@ -2231,7 +2225,7 @@ - (void)handleApplicationWillEnterForeground:(NSNotification *)notification { #if TARGET_OS_IOS == 1 #ifndef MPARTICLE_LOCATION_DISABLE [MParticle executeOnMain:^{ - if ([MPLocationManager trackingLocation] && ![MParticle sharedInstance].stateMachine.locationManager.backgroundLocationTracking) { + if ([MPLocationManager_PRIVATE trackingLocation] && ![MParticle sharedInstance].stateMachine.locationManager.backgroundLocationTracking) { [[MParticle sharedInstance].stateMachine.locationManager.locationManager startUpdatingLocation]; } }]; diff --git a/mParticle-Apple-SDK/Utils/MPMessageBuilder.m b/mParticle-Apple-SDK/Utils/MPMessageBuilder.m index a565ea24..f66cffdd 100644 --- a/mParticle-Apple-SDK/Utils/MPMessageBuilder.m +++ b/mParticle-Apple-SDK/Utils/MPMessageBuilder.m @@ -9,14 +9,12 @@ #import "MPCommerceEvent+Dictionary.h" #import "MPILogger.h" #import "NSDictionary+MPCaseInsensitive.h" -#ifndef MPARTICLE_LOCATION_DISABLE -#import "MPLocationManager.h" -#endif #import "MPUserAttributeChange.h" #import "MPUserIdentityChange.h" #import "MPPersistenceController.h" #import "MPApplication.h" #import "mParticle.h" +#import "MParticleSwift.h" NSString *const launchInfoStringFormat = @"%@%@%@=%@"; NSString *const kMPHorizontalAccuracyKey = @"acc"; diff --git a/mParticle-Apple-SDK/Utils/MPStateMachine.h b/mParticle-Apple-SDK/Utils/MPStateMachine.h index bd705f00..debbd762 100644 --- a/mParticle-Apple-SDK/Utils/MPStateMachine.h +++ b/mParticle-Apple-SDK/Utils/MPStateMachine.h @@ -9,7 +9,7 @@ #if TARGET_OS_IOS == 1 #ifndef MPARTICLE_LOCATION_DISABLE @class CLLocation; - @class MPLocationManager; + @class MPLocationManager_PRIVATE; #endif #endif @class MPCustomModule; @@ -29,7 +29,7 @@ #if TARGET_OS_IOS == 1 #ifndef MPARTICLE_LOCATION_DISABLE @property (nonatomic, strong, nullable) CLLocation *location; -@property (nonatomic, strong, nullable) MPLocationManager *locationManager; +@property (nonatomic, strong, nullable) MPLocationManager_PRIVATE *locationManager; #endif #endif @property (nonatomic, strong, nullable) NSString *networkPerformanceMeasuringMode; diff --git a/mParticle-Apple-SDK/Utils/MPStateMachine.m b/mParticle-Apple-SDK/Utils/MPStateMachine.m index 5e5ca374..1fa5bec9 100644 --- a/mParticle-Apple-SDK/Utils/MPStateMachine.m +++ b/mParticle-Apple-SDK/Utils/MPStateMachine.m @@ -10,9 +10,6 @@ #import "MPILogger.h" #import "MPConsumerInfo.h" #import "MPPersistenceController.h" -#ifndef MPARTICLE_LOCATION_DISABLE -#import "MPLocationManager.h" -#endif #import "MPKitContainer.h" #if TARGET_OS_IOS == 1 #import "MPSearchAdsAttribution.h" @@ -474,7 +471,7 @@ - (void)setInstallationType:(MPInstallationType)installationType { #if TARGET_OS_IOS == 1 #ifndef MPARTICLE_LOCATION_DISABLE - (CLLocation *)location { - if ([MPLocationManager trackingLocation]) { + if ([MPLocationManager_PRIVATE trackingLocation]) { return self.locationManager.location; } else { return _location; @@ -482,7 +479,7 @@ - (CLLocation *)location { } - (void)setLocation:(CLLocation *)location { - if ([MPLocationManager trackingLocation]) { + if ([MPLocationManager_PRIVATE trackingLocation]) { if (self.locationManager) { self.locationManager.location = location; } diff --git a/mParticle-Apple-SDK/mParticle.m b/mParticle-Apple-SDK/mParticle.m index cd344887..4f2254b3 100644 --- a/mParticle-Apple-SDK/mParticle.m +++ b/mParticle-Apple-SDK/mParticle.m @@ -26,12 +26,6 @@ #import "MParticleSwift.h" #import "MPUpload.h" -#if TARGET_OS_IOS == 1 -#ifndef MPARTICLE_LOCATION_DISABLE - #import "MPLocationManager.h" -#endif -#endif - static dispatch_queue_t messageQueue = nil; static void *messageQueueKey = "mparticle message queue key"; static void *messageQueueToken = "mparticle message queue token";