SDK Installation
1. Add dependencies
Cocoapods
- Add dependency to
Podfile
.
`pod 'Amplitude', '~> 7.2.0'`
- Run
pod install
in the project directory to download dependency.
Swift Package Manager
File
->Swift Package Manager
->Add Package Dependency


- Type in
https://github.com/amplitude/Amplitude-iOS
when choosing package repo.


- It will automatically resolve it and located to the latest version.


- After successfully being added, it will show up as a dependency.


Carthage
- Please add the following line to your
Cartfile
.
github "amplitude/Amplitude-iOS" ~> 7.2.0
- Add
#import <Amplitude/Amplitude.h>
to import all of the Amplitude header files.
2. iOS advertising Id (Optional)
Please refer to this.
3. Carrier information (Optional)
Please refer to this.
Quick Start
1. Import package/class
#import <Amplitude/Amplitude.h>
import Amplitude
2. Initialize and log an event
// Usually you can initialize the SDK in the `application:didFinishLaunchingWithOptions:` method of your YourAppAppDelegate.m file
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Enable sending automatic session events
[Amplitude instance].trackingSessionEvents = YES;
// Initialize SDK
[[Amplitude instance] initializeApiKey:@"API_KEY"];
// Set userId
[[Amplitude instance] setUserId:@"userId"];
// Log an event
[[Amplitude instance] logEvent:@"app_start"];
return YES;
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Enable sending automatic session events
Amplitude.instance()?.trackingSessionEvents = true
// Initialize SDK
Amplitude.instance()?.initializeApiKey("API_KEY")
// Set userId
Amplitude.instance()?.setUserId("userId")
// Log an event
Amplitude.instance()?.logEvent("app_start")
return true
}
Usage & Examples
Please see the SDK Usage & Examples page.
Need Help?
If you have any problems or issues over our SDK, feel free to create a github issue or submit a request on Amplitude Help.
Updated 3 months ago