import BMSCore
import BMSAnalytics
Next you'll need to initialize and send mobile analytics in your didFinishLaunchingWithOptions method:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Set api key, Bluemix region. These are available in the Mobile Analytics console after you create an instance
let api_key="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
let bmixRegion=BMSClient.Region.usSouth
//Provide a name for your app that will appear in the Mobile Analytics console.
let appName="MyAppName"
//Initialize Mobile Analytics in your Bluemix region
BMSClient.sharedInstance.initialize(bluemixRegion: bmixRegion)
Analytics.initialize(appName: appName, apiKey: api_key, hasUserContext: false,
deviceEvents: DeviceEvent.LIFECYCLE)
//Send analytics
//Analytics.send()
//Alternately send analytics and log to your xCode console
Analytics.send { (response: Response?, error: NSError?) in
if response?.statusCode == 201 {
print("Successfully sent analytics: \(response?.responseText)")
}
else {
print("Failed to send analytics: \(response?.responseText). Error: \(error?.localizedDescription)")
}
}
return true
}
Add Analytics.send()
into your app code everywhere you want the analytics stored in the app to be sent to the Mobile Analytics for Bluemix service.
Run your app. You will see a new user and a new session in your analytics console.