Advanced mode

Connect/Create an account automatically

Use the method [APMUIServicesUser userClientConnect] for connect automatically your user to app’s miles. If no account exist with this informations, the server create automatically this account. This method needs : « email », « userID » and « optIn » « email » is the email of user « userID » is a unique identifier in your database – « optIn » is the RGPD OptIn

If you don’t want pass the email, you can build a encrypted email with the userID, for example : 123456789@appsmiles.fr – 123456789 is the userID

NSString* email = _textFieldEmail.text; //Required 
NSString* userId = _textFieldUserId.text; //Required 

//optIn, APM_DEVICE_OPT_IN_NOT_SET, APM_DEVICE_OPT_IN_REFUSE, APM_DEVICE_OPT_IN_ACCEPT 
NSNumber* optIn = APM_DEVICE_OPT_IN_ACCEPT; //Required 

[APMUIServicesUser userClientConnect:email 
                     partnerClientId:userId 
                               optIn:optIn 
                  userConnectSuccess:^(APMUser *user) {     
    NSLog(@"%@ --> connected !", user); 
} failure:^(NSError *error) {     
    NSLog(@"%@", error); 
}];

Update an account automatically

You can update an app’s miles account automatically with the method [APMUIServicesUser userClientSave]

This method needs : « userId »

NSString* email = _textFieldEmail.text;
NSString* firstname = _textFieldFirstname.text;
NSString* lastname = _textFieldLastname.text;
NSString* mobile = _textFieldMobile.text;
NSString* city = _textFieldCity.text;
NSString* gender = [NSString stringWithFormat:@"%li", (long)APM_K_USER_GENDER_M];
NSString* birthday = _textFieldBirthday.text;
NSString* userId = _textFieldUserId.text;
NSMutableDictionary* segments = nil;

[APMUIServicesUser userClientSave:email 
                        firstname:firstname 
                         lastname:lastname 
                           mobile:mobile 
                           gender:gender 
                         birthday:birthday 
                             city:city 
                       facebookId:nil 
                  partnerClientId:userId 
                         segments:segments
                  userSaveSuccess:^(APMUser *user)
 {
     NSLog(@"%@ --> updated !", user);
 } failure:^(NSError *error)
 {
     NSLog(@"%@", error);
 }];

Logout an account automatically

You can logout an app’s miles account automatically with the method [APMUIServicesUser userLogout]

[APMUIServicesUser userLogout:^{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Logout" message:@"Logout success" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
    [alert show];
} failure:^(NSError *error) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Logout" message:error.localizedDescription delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
    [alert show];
}];

The badge is automatically refreshes

UserProperties

Use the class APMUserPropertiesUtils to manager user properties fo user.

key : Property keys are strings. (e.g. « zipcode », « profession »). value :Property values are strings. (e.g. « 33000 », « doctor »).

You can add user properties with the followings methods :

-(void)addUserProperty:(NSString*)userProperty forKey:(NSString*)key;
-(void)addUserProperties:(NSDictionary*)userProperties;

For remove one user property, you can use :

-(void)removeUserProperty:(NSString*)key

or for remove all user properties :

-(void)removeUserProperties

If you need to refresh SDK after set your UserProperties, you can call :

[[APMServices sharedInstance] refreshSDK:YES];

Segments

You can pass a segmentation during connection with the method [APMUIServicesUser.userClientConnect]

//Segments
NSMutableDictionary* segments = [NSMutableDictionary dictionary];
[segments setValue:@"green" forKey:@"1"]; //Axe 1 : color
[segments setValue:@"1998" forKey:@"2"]; //Axe 2 : year
 
[APMUIServicesUser userClientConnect/*....*/ segments:segments /*....*/];

Override click on the badge

You can override the click on the badge with the method [APMBadgeManager setOnBadgeClick]

APMBadgeManager *badgeManager = [APM sharedInstanceBadgeManager];
[badgeManager setOnBadgeClick:^BOOL(NSInteger badge) {
    if(badge == APM_BADGE_INIT)
        NSLog(@"Click on the badge init !");
    else if(badge == APM_BADGE_OTHER_WIN)
        NSLog(@"Click on the badge other win !");
    else if(badge == APM_BADGE_WIN)
        NSLog(@"Click on the badge win !");
    else if(badge == APM_BADGE_GIFT)
        NSLog(@"Click on the badge gift !");
    else if(badge == APM_BADGE_INFOS)
        NSLog(@"Click on the badge infos !");
    else if(badge == APM_BADGE_ADMIN)
        NSLog(@"Click on the badge admin !");
    return true;
}];

Comment : Return true if the event was handled, false otherwise.

Show/Hide badge

You can hide the badge with the method :

[[APM sharedInstance] hideBadge];

And show the badge :

[[APM sharedInstance] showBadge];

Comment : The method APMUIServicesUser.userClientConnect() use theses methods to hide and show the badge after connection success.

Debug Mode

[APM sharedInstance].debugMode = YES; //To show trace log app's miles

Onboarding (get events with listener)

For retrieve events of onboarding. Use class APMOnboardingUtils and APMOnboardingUtilsListener. Example with AbstractViewController lifecycle.

@interface AbstractViewController() <APMOnboardingUtilsListener>

//...

//Declare a object of APMOnboardingUtils in your class
@property (strong, nonatomic) APMOnboardingUtils* onboardingUtils;

@end

@implementation AbstractViewController

-(void)viewDidLoad
{
    [super viewDidLoad];
    //...

    //AbstractViewController become the listener on events of onboarding
    self.onboardingUtils = [[APMOnboardingUtils alloc] init];
    self.onboardingUtils.delegate = self;
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    //...
 
    //Listen events of onboarding
    [self.onboardingUtils registerNotifications];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    //...
 
    //Unlisten events of onboarding
    [self.onboardingUtils unregisterNotifications];
}

#pragma mark - APMOnboardingUtilsListener

-(void)apmOnboardingButtonOkClicked
{
    //Get the event OnboardingButtonOkClicked
}

-(void)apmOnboardingButtonLaterClicked
{
    //Get the event OnboardingButtonLaterClicked
}

-(void)apmOnboardingButtonNeverClicked
{
    //Get the event OnboardingButtonNeverClicked
}

@end

For retrieve events of deepLinks. Use class APMDeepLinkActionUtils and APMDeepLinkActionUtilsListener. Example with AbstractViewController lifecycle.

@interface AbstractViewController() <APMDeepLinkActionUtilsListener>

//...

//Declare a object of APMDeepLinkActionUtils in your class
@property (strong, nonatomic) APMDeepLinkActionUtils* deepLinkActionUtils;

@end

@implementation AbstractViewController

-(void)viewDidLoad
{
    [super viewDidLoad];
    //...
 
    //Activity become the listener on events of deeplinks
    self.deepLinkActionUtils = [[APMDeepLinkActionUtils alloc] init];
    self.deepLinkActionUtils.delegate = self;
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    //...
 
    //Listen events of deeplinks
    [self.deepLinkActionUtils registerNotifications];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    //...
 
    //Unlisten events of deeplinks
    [self.deepLinkActionUtils unregisterNotifications];
}

#pragma mark - APMDeepLinkActionUtilsListener

-(void)apmDeepLinkActionButtonGoClicked:(NSString *)url action:(NSString *)action params:(NSMutableDictionary *)params
{
    //Get the event DeepLinkActionButtonGoClicked
}

@end

APMServicesUserListener

You can be notify when the user changed with the class APMServicesUserListener Set a listener with

[APMServices sharedInstance].servicesUserListener = self;

Get the callback with the method apmServicesUserChanged

#pragma mark - APMServicesUserListener
-(void)apmServicesUserChanged:(APMUser *)user
{
    NSLog(@"apmServicesUserChanged : %@", user);
}

Communicate with a WebView

You can communicate with APM natively with your Webview. Here, methods that reachable via APMJavaScriptInterface :

  • [[APM sharedInstance] registerAction:<ACTION>];

  • [[APM sharedInstance] triggerAction:<ACTION_NAME>];

In your MainViewController.m, override method [webView:shouldStartLoadWithRequest:navigationType]

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    BOOL urlCatched = [APMJavaScriptInterface webView:webView handleUrlSchemeAppsmiles:request];
    if(urlCatched) //Url catched, so return NO for webView don't load url
        return NO;
    return YES;
}

Implement this JS method :

function execute(url) 
{
    var iframe = document.createElement("IFRAME");
    iframe.setAttribute("src", url);
    document.documentElement.appendChild(iframe);
    iframe.parentNode.removeChild(iframe);
    iframe = null;
}

registerAction(IOS) == addActions(JS)

Call addActions appsmilessdk://addActions/+PARAMS in your webview to call registerAction in IOS PARAMS is a JSONObject converted to String :

{
    "classID":"product", 
    "actions":
        [
            {
                "labels":["label 1", "label 2", "label 3"], 
                "props":["property 1", "property 2", "property 3"]
            }
        ]
}

Example :

execute("appsmilessdk://addActions/{"classID":"product", "actions":[{"labels":["Clic sur un produit", "Clic sur un produit de la catégorie Google", "Clic sur le produit GOOGLE !"], "props":["click_product", "categoryID=1", "productID=1"]}]}");

triggerAction(IOS) == triggerAction(JS)

Call triggerAction appsmilessdk://triggerAction/+ACTION_NAME in your webview to call triggerActionin IOS ACTION_NAME is a String

Example :

execute("appsmilessdk://triggerAction/click_product"); //click_product == ACTION_NAME

Last updated