Install

1. Install

Conditions

Version IOS minimum : 7.0 Version XCode minimum : 7

Install framework using CocoaPods

pod 'APM', '~> 3.1.8'

Install framework Manually

  • Download framework APM (3.1.8) here

Note : The APM SDK for iOS provides much functionality and countless customization options at high performance, requiring somewhat more storage space than a simpler framework would. Nonetheless, the SDK contributes only 4 MB to the ultimate size of your application, thanks to various optimization steps that occur during the compilation and App Store submission processes.

2. Integration

Configuration

Set in your info.plist :

  • APMPartnerID

  • APMPartnerSecret

Initialize APM, in your « AppDelegate »

In YourAppDelegate.h, import APMHeaders.h

#import <APM/APMHeaders.h>

In YourAppDelegate.m, implements URL Scheme callback

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
BOOL urlCatched = [[APM sharedInstance] handleOpenURL:url];
return urlCatched;
}

In method application:didFinishLaunchingWithOptions: Retrieve instance of APM

APM *apm = [APM sharedInstance];

Set the baseUrl of API https://api.appsmiles.eu/ (PRODUCTION) https://api-sandbox.appsmiles.eu/ (SANDOX)

apm.baseUrl = <URL_API>;

Enable APM for a « ViewController »

Import APMHeaders.h

#import <APM/APMHeaders.h>

Add the following methods in your UIViewController

  • [[APM sharedInstance] viewWillAppear:animated];

  • [[APM sharedInstance] viewDidAppear:animated];

  • [[APM sharedInstance] viewWillDisappear:animated];

  • [[APM sharedInstance] viewDidDisappear:animated];

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[APM sharedInstance] viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [[APM sharedInstance] viewDidAppear:animated];  
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[APM sharedInstance] viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [[APM sharedInstance] viewDidDisappear:animated];
}

You can launch the app, the banner or the sticker will be appear now.

3. Connection client

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);
 }];

4. Show/Hide badge

If you want to hide the badge on some screens

[[APM sharedInstance] hideBadge];

Don’t forget to re-show badge after hiding

[[APM sharedInstance] showBadge];

5. Tagging plan

Call triggerAction for send a tag

[[APM sharedInstance] triggerAction:@"display_product"]; //"display_product" --> actionName

6. Onboarding process

Implements this for :– app’s miles account and client account not connected, so, redirect user to your process login/register account– app’s miles account not connected and client account connected, so, connect app’s miles account with method userClientConnect– app’s miles account and client account connected, so, nothing

@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
    BOOL clientAccountConnected = YES;
    if(clientAccountConnected) //TODO check if account client is connected
    {
        //Account client is connected
        
        APMServices* services = [APMServices sharedInstance];
        if(services.user && [services.user isConnected])
        {
            //Client account connected and app's miles account connected
            NSLog(@"Client account connected and app's miles account connected");
        }
        else
        {
            //Client account connected --> need to connect app's miles account
            NSLog(@"Client account connected --> need to connect app's miles account");
            [YourAppDelegate apmConnection];
        }
    }
    else
    {
        //TODO show screen login/create account
    }
}
-(void)apmOnboardingButtonLaterClicked { }
-(void)apmOnboardingButtonNeverClicked { }

@end

Last updated