{"_id":"57b96d6c1d08500e00bf822a","project":"54861bb654b3ce0b00367292","__v":1,"category":{"_id":"57b96d6b1d08500e00bf81d3","project":"54861bb654b3ce0b00367292","version":"57b96d6b1d08500e00bf81d1","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-12-08T21:55:25.679Z","from_sync":false,"order":1,"slug":"1-setup","title":"iOS / App Triggers"},"user":"548d74b716fc980b00e2a786","parentDoc":null,"version":{"_id":"57b96d6b1d08500e00bf81d1","__v":7,"project":"54861bb654b3ce0b00367292","createdAt":"2016-08-21T08:59:23.326Z","releaseDate":"2016-08-21T08:59:23.326Z","categories":["57b96d6b1d08500e00bf81d2","57b96d6b1d08500e00bf81d3","57b96d6b1d08500e00bf81d4","57b96d6b1d08500e00bf81d5","57b96d6b1d08500e00bf81d6","57b96d6b1d08500e00bf81d7","57b96d6b1d08500e00bf81d8","57b96d6b1d08500e00bf81d9","57b96d6b1d08500e00bf81da","57b96d6b1d08500e00bf81db","57b96d6b1d08500e00bf81dc","57b97748306b9b0e001dd53f","57d12c6c1227b40e0044908a","57d51ad68191880e008bb51b","57d52b5cf350090e00fe073e","57d5468a17b492170053a3f0","57df9df05927cb0e002bce1e"],"is_deprecated":true,"is_hidden":false,"is_beta":false,"is_stable":false,"codename":"","version_clean":"4.0.0","version":"4.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-12-17T15:42:54.326Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":12,"body":"[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//\\n//  AppDelegate.m\\n//\\n//  Created by Tomer Shkolnik.\\n//  Copyright © 2015 elasticode. All rights reserved.\\n//\\n\\n#import \\\"AppDelegate.h\\\"\\n#import <ElastiCode/ElastiCode.h>\\n:::at:::interface AppDelegate ()\\n@end\\n\\n@implementation AppDelegate\\n\\n- (BOOL)application:(UIApplication *)application \\n  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\\n\\t\\t\\n    // basic setup \\n\\t  [ElastiCode setAPIKey:@\\\"<APIKey>\\\"];\\n    [ElastiCode setLaunchingOptions:launchOptions];\\n    [ElastiCode setOnLaunchCompletionBlock:^(BOOL didAppear) {}];\\n\\t\\t\\n    // app triggers basic setup\\n    ECSessionParams* params = [ECSessionParams createInProduction:NO];\\n    \\n    // apply configurations...\\n    \\n    // Define moments:\\n    [params.data defineAppTrigger:@\\\"New feature tour\\\"\\n                 isActiveCallback:^(BOOL isActive) {\\n    }];\\n    \\n    // Define backView section:\\n   \\t[params.data defineBackViewSection:@\\\"Checkout\\\"];\\n    \\n    // Define case:\\n    [params.data defineCase:@\\\"caseName\\\" withNumOfStates:3];\\n    \\n    // Define dynamic object:\\n    [params.data defineDynamicObject:@\\\"DynamicObjectNmae\\\" \\n     type:(ElastiCodeDObjType_arrayOfInt) defaultValue:@[@(100), @(200), @(300)]];\\n    \\n    // Set ThirdParty Analytics - Mixpanel\\n    [ElastiCode setThirdPartyAnalytics:@\\\"Mixpanel\\\"\\n                                 action:^(NSString * _Nonnull eventName) {\\n                                     Mixpanel *mixpanel = [Mixpanel sharedInstance];\\n                                     [mixpanel track:eventName properties:@{}];\\n                                 }];\\n    \\n    // Add actions for buttons\\n    [ElastiCode setActions:@[\\n                              [ECOnBoardingAction createWithName:@\\\"Ask for permission\\\"\\n                                                          action:^{\\n                                                              // permission logic\\n                                                          }]\\n                              ]];\\n    \\n    // Register to notifications\\n    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_sessionStartedNotification:) name:ELASTICODE_SESSION_STARTED object:nil];\\n    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_sessionRestartedNotification:) name:ELASTICODE_SESSION_RESTARTED object:nil];\\n    \\n    [ElastiCode setSessionParams:params];\\n    [ElastiCode ready];\\n    \\n    return YES;\\n}\\n\\n-(BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<NSString *,id> *)options\\n{\\n    return [ElastiCode openURL:url completion:^(BOOL didAppear) {\\n        \\n    }];\\n}\\n- (void)applicationWillResignActive:(UIApplication *)application {}\\n- (void)applicationDidEnterBackground:(UIApplication *)application {}\\n- (void)applicationWillEnterForeground:(UIApplication *)application {}\\n- (void)applicationDidBecomeActive:(UIApplication *)application {}\\n- (void)applicationWillTerminate:(UIApplication *)application {}\\n\\n-(void) _sessionStartedNotification:(NSNotification*) note { }\\n-(void) _sessionRestartedNotification:(NSNotification*) note { }\\n\\n@end\\n  \",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"//\\n//  AppDelegate.swift\\n//\\n//  Created by Tomer Shkolnik.\\n//  Copyright © 2015 elasticode. All rights reserved.\\n//\\n\\nimport UIKit\\n\\n@UIApplicationMain\\nclass AppDelegate: UIResponder, UIApplicationDelegate {\\n\\n    var window: UIWindow?\\n    \\n    func application(application: UIApplication, didFinishLaunchingWithOptions\\n        launchOptions: [NSObject: AnyObject]?) -> Bool {\\n        \\n        // basic setup\\n        ElastiCode.setAPIKey(\\\"<APIKey>\\\")\\n        ElastiCode .setLaunchingOptions(launchOptions)\\n        ElastiCode .setOnBoardingCompletionBlock { (didAppear) in}\\n        \\n        // app triggers basic setup\\n        let params:ECSessionParams = ECSessionParams .createInProduction(false)\\n        \\n        // Define moments:\\n        params.data .defineMoment(\\\"New feature tour\\\")\\n        \\n        // Define backView section:\\n        params.data .defineBackViewSection(\\\"Checkout\\\")\\n        \\n        // Define case:\\n        params.data .defineCase(\\\"caseName\\\", withNumOfStates: 3)\\n        \\n        // Define dynamic object:\\n        params.data .defineDynamicObject(\\\"DynamicObjectNmae\\\",\\n                                         type: ElastiCodeDObjType_arrayOfInt,\\n                                         defaultValue: [(100), (200), (300)])\\n        \\n        // Set ThirdParty Analytics - Mixpanel\\n        ElastiCode .setThirdPartyAnalytics(\\\"Mixpanel\\\") { (eventName) -> Void in\\n            mixpanel.track(eventName,properties: [])\\n        }\\n        \\n        // Add actions for buttons\\n        ElastiCode .setActions([\\n            ECOnBoardingAction .createWithName(\\\"Ask for permission\\\",\\n                action: { ([NSObject : AnyObject]) -> Void in\\n                    // permission logic\\n            })\\n            ]\\n        )\\n        NSNotificationCenter.defaultCenter()\\n            .addObserver(self, selector: #selector(_sessionStartedNotification),\\n                         name: ELASTICODE_SESSION_STARTED, object: nil\\n        )\\n        NSNotificationCenter.defaultCenter()\\n            .addObserver(self, selector: #selector(_sessionRestartedNotification),\\n                         name: ELASTICODE_SESSION_RESTARTED, object: nil\\n        )\\n        \\n        ElastiCode .setSessionParams(params)\\n        ElastiCode .ready()\\n            \\n        return true\\n    }\\n    \\n    func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {\\n        return ElastiCode.openURL(url, completion: { (didAppear) in\\n            \\n        })\\n    }\\n    func applicationWillResignActive(application: UIApplication) {}\\n    func applicationDidEnterBackground(application: UIApplication) {}\\n    func applicationWillEnterForeground(application: UIApplication) {}\\n    func applicationDidBecomeActive(application: UIApplication) {}\\n    func applicationWillTerminate(application: UIApplication) {}\\n    \\n    func _sessionStartedNotification(notif: NSNotification) {}\\n    func _sessionRestartedNotification(notif: NSNotification) {}\\n}\\n\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]","excerpt":"IOS / APP TRIGGERS: AppDelegate Example","slug":"appdelegate-example-advanced","type":"basic","title":"AppDelegate Example (Advanced)"}

AppDelegate Example (Advanced)

IOS / APP TRIGGERS: AppDelegate Example

[block:code] { "codes": [ { "code": "//\n// AppDelegate.m\n//\n// Created by Tomer Shkolnik.\n// Copyright © 2015 elasticode. All rights reserved.\n//\n\n#import \"AppDelegate.h\"\n#import <ElastiCode/ElastiCode.h>\n@interface AppDelegate ()\n@end\n\n@implementation AppDelegate\n\n- (BOOL)application:(UIApplication *)application \n didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n\t\t\n // basic setup \n\t [ElastiCode setAPIKey:@\"<APIKey>\"];\n [ElastiCode setLaunchingOptions:launchOptions];\n [ElastiCode setOnLaunchCompletionBlock:^(BOOL didAppear) {}];\n\t\t\n // app triggers basic setup\n ECSessionParams* params = [ECSessionParams createInProduction:NO];\n \n // apply configurations...\n \n // Define moments:\n [params.data defineAppTrigger:@\"New feature tour\"\n isActiveCallback:^(BOOL isActive) {\n }];\n \n // Define backView section:\n \t[params.data defineBackViewSection:@\"Checkout\"];\n \n // Define case:\n [params.data defineCase:@\"caseName\" withNumOfStates:3];\n \n // Define dynamic object:\n [params.data defineDynamicObject:@\"DynamicObjectNmae\" \n type:(ElastiCodeDObjType_arrayOfInt) defaultValue:@[@(100), @(200), @(300)]];\n \n // Set ThirdParty Analytics - Mixpanel\n [ElastiCode setThirdPartyAnalytics:@\"Mixpanel\"\n action:^(NSString * _Nonnull eventName) {\n Mixpanel *mixpanel = [Mixpanel sharedInstance];\n [mixpanel track:eventName properties:@{}];\n }];\n \n // Add actions for buttons\n [ElastiCode setActions:@[\n [ECOnBoardingAction createWithName:@\"Ask for permission\"\n action:^{\n // permission logic\n }]\n ]];\n \n // Register to notifications\n [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_sessionStartedNotification:) name:ELASTICODE_SESSION_STARTED object:nil];\n [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_sessionRestartedNotification:) name:ELASTICODE_SESSION_RESTARTED object:nil];\n \n [ElastiCode setSessionParams:params];\n [ElastiCode ready];\n \n return YES;\n}\n\n-(BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<NSString *,id> *)options\n{\n return [ElastiCode openURL:url completion:^(BOOL didAppear) {\n \n }];\n}\n- (void)applicationWillResignActive:(UIApplication *)application {}\n- (void)applicationDidEnterBackground:(UIApplication *)application {}\n- (void)applicationWillEnterForeground:(UIApplication *)application {}\n- (void)applicationDidBecomeActive:(UIApplication *)application {}\n- (void)applicationWillTerminate:(UIApplication *)application {}\n\n-(void) _sessionStartedNotification:(NSNotification*) note { }\n-(void) _sessionRestartedNotification:(NSNotification*) note { }\n\n@end\n ", "language": "objectivec" }, { "code": "//\n// AppDelegate.swift\n//\n// Created by Tomer Shkolnik.\n// Copyright © 2015 elasticode. All rights reserved.\n//\n\nimport UIKit\n\n@UIApplicationMain\nclass AppDelegate: UIResponder, UIApplicationDelegate {\n\n var window: UIWindow?\n \n func application(application: UIApplication, didFinishLaunchingWithOptions\n launchOptions: [NSObject: AnyObject]?) -> Bool {\n \n // basic setup\n ElastiCode.setAPIKey(\"<APIKey>\")\n ElastiCode .setLaunchingOptions(launchOptions)\n ElastiCode .setOnBoardingCompletionBlock { (didAppear) in}\n \n // app triggers basic setup\n let params:ECSessionParams = ECSessionParams .createInProduction(false)\n \n // Define moments:\n params.data .defineMoment(\"New feature tour\")\n \n // Define backView section:\n params.data .defineBackViewSection(\"Checkout\")\n \n // Define case:\n params.data .defineCase(\"caseName\", withNumOfStates: 3)\n \n // Define dynamic object:\n params.data .defineDynamicObject(\"DynamicObjectNmae\",\n type: ElastiCodeDObjType_arrayOfInt,\n defaultValue: [(100), (200), (300)])\n \n // Set ThirdParty Analytics - Mixpanel\n ElastiCode .setThirdPartyAnalytics(\"Mixpanel\") { (eventName) -> Void in\n mixpanel.track(eventName,properties: [])\n }\n \n // Add actions for buttons\n ElastiCode .setActions([\n ECOnBoardingAction .createWithName(\"Ask for permission\",\n action: { ([NSObject : AnyObject]) -> Void in\n // permission logic\n })\n ]\n )\n NSNotificationCenter.defaultCenter()\n .addObserver(self, selector: #selector(_sessionStartedNotification),\n name: ELASTICODE_SESSION_STARTED, object: nil\n )\n NSNotificationCenter.defaultCenter()\n .addObserver(self, selector: #selector(_sessionRestartedNotification),\n name: ELASTICODE_SESSION_RESTARTED, object: nil\n )\n \n ElastiCode .setSessionParams(params)\n ElastiCode .ready()\n \n return true\n }\n \n func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {\n return ElastiCode.openURL(url, completion: { (didAppear) in\n \n })\n }\n func applicationWillResignActive(application: UIApplication) {}\n func applicationDidEnterBackground(application: UIApplication) {}\n func applicationWillEnterForeground(application: UIApplication) {}\n func applicationDidBecomeActive(application: UIApplication) {}\n func applicationWillTerminate(application: UIApplication) {}\n \n func _sessionStartedNotification(notif: NSNotification) {}\n func _sessionRestartedNotification(notif: NSNotification) {}\n}\n", "language": "swift" } ] } [/block]