You can use the CleverTapLocation
module to get the user's location (and possibly track the location for events).
- Cocoapods
- Swift Package Manager
- Manual Installation
Add the following to your Podfile:
target 'YOUR_TARGET_NAME' do
pod 'CleverTapLocation'
end
Then run pod install.
- Open your project and navigate to the project's settings. Select the tab named Swift Packages and click on the add button (+) at the bottom left.
- Enter the URL of CleverTap GitHub repository - https://github.com/CleverTap/clevertap-ios-sdk.git and click Next.
- On the next screen, select the preferred SDK version and click Next.
- Click finish and ensure that the CleverTapLocation has been added to the appropriate target.
-
Clone the CleverTap iOS SDK repository recursively:
git clone --recursive https://github.com/CleverTap/clevertap-ios-sdk.git
-
Navigate to
CleverTapLocation
folder and add theCleverTapLocation.xcodeproj
to your Xcode Project, by dragging theCleverTapLocation.xcodeproj
under the main project file. -
Navigate to the project application’s target settings, open "General", click the "+" button under the "Frameworks, Libraries, and Embedded Content", add CleverTapLocation.framework as an embedded binary.
// Swift
import CleverTapLocation
CTLocationManager.getLocationWithSuccess { coordinate in
print(coordinate)
} andError: { reason in
print(reason)
}
// Objective-C
#import <CleverTapLocation/CTLocationManager.h>
[CTLocationManager getLocationWithSuccess:^(CLLocationCoordinate2D location) {
NSLog(@"%@",location);
} andError:^(NSString *reason) {
NSLog(@"%@",reason);
}];