Growthbeat SDK with Swift - growthbeat/Growthbeat-SDK-iOS-Starter-Project GitHub Wiki
1. Add the Growthbeat SDK to your Xcode Project
CocoaPods
$ pods install- In Xcode create
growthbeat.plistand right-click and choose "Open As > Source Code". - Add
YOUR_APLICATION_IDandYOUR_CREDENTIAL_IDlike below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>GrowthbeatAppID</key>
<string>{YOUR_APLICATION_ID}</string>
<key>GrowthbeatCredentialID</key>
<string>{YOUR_CREDENTIAL_ID}</string>
</dict>
</plist>Growthbeat SDK is written with Objective-C so You need to create <project name>-Bridging-Header.h to use file written in Objective-C in Swift Project. New File ... -> Header File -> <project name>-Bridging-Header.h -> Create and then a file will be generated.
Add #import <Growthbeat/Growthbeat.h> in <project name>-Bridging-Header.h:
#import <Growthbeat/Growthbeat.h>And you need to configure to import <project name>-Brighing-Header.h when compiling Swift project. Target -> Build Setting -> Swift Compiler - Code Generation -> Objective-C Bridging Header. You add it below:
$(SRCROOT)/$(PROJECT)/$(PROJECT)-Bridging-Header.h

Growthbeat.sharedInstance().initializeWithApplicationId("APPLICATION_TOKEN", credentialId: "YOUR_CREDENTIALID");@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
#if DEBUG
let kGPEnvironment:GPEnvironment = GPEnvironment.Development
#else
let kGPEnvironment:GPEnvironment = GPEnvironment.Production
#endifBuild Settings -> Swift Compiler - Custome Flag Other Swift Flags:
-D DEBUG

GrowthPush.sharedInstance().requestDeviceTokenWithEnvironment(kGPEnvironment)func application( application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData ) {
GrowthPush.sharedInstance().setDeviceToken(deviceToken)
}After all minimum AppDelegate.swift will be like below:
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
+ #if DEBUG
+ let kGPEnvironment:GPEnvironment = GPEnvironment.Development
+ #else
+ let kGPEnvironment:GPEnvironment = GPEnvironment.Production
+ #endif
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
+ Growthbeat.sharedInstance().initializeWithApplicationId("APPLICATION_TOKEN", credentialId: "YOUR_CREDENTIALID");
+ GrowthPush.sharedInstance().requestDeviceTokenWithEnvironment(kGPEnvironment)
return true
}
+ func application( application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData ) {
+ GrowthPush.sharedInstance().setDeviceToken(deviceToken)
+ }