Implementação Objective-C

Para integrar a SDK Inngage ao seu aplicativo desenvolvido em Objective-C siga os passos a seguir.

1. No arquivo **Info.plist** adicione as seguintes chaves **InngageAppToken** e **InngageApiEndpoint**. Onde:

  • InngageAppToken – corresponde ao token de acesso do aplicativo, e pode ser obtido na plataforma **Inngage** em Configurações do App > Aplication ID. *O token de autenticação é único, e varia de acordo com o ambiente.*
  • InngageApiEndpoint – corresponde ao endpoint da nossa API. Ambiente de *sandbox* (desenvolvimento): https://apid.inngage.com.br/v1 Ambiente de *produção*: https://api.inngage.com.br/v1
<plist version="1.0">
<dict>
	<key>InngageApiEndpoint</key>
	<string>https://apid.inngage.com.br/v1</string>
	<key>InngageAppToken</key>
	<string>seu_app_token_aqui</string>
</dict>
</plist>

🚧

As implementações abaixo deverão ser feitas no arquivo AppDelegate.m

2. Adicione a importação da biblioteca:

#import "PushNotificationManager.h"

3. Declare as seguintes variáveis:

@interface AppDelegate (){
    
    PushNotificationManager * manager;
    NSDictionary *userInfoNotification;
}

4. Adicione a seguinte implementação no corpo do método **didFinishLaunchingWithOptions**:

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    userInfoNotification = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    
    if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:
                                                                             (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    }
    
    if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {
        [self application:application didReceiveRemoteNotification:launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]];
    }
    
    manager = [PushNotificationManager sharedInstance ];
    return YES;
}

5. Implemente o método **didRegisterUserNotificationSettings**:

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings: (UIUserNotificationSettings *)notificationSettings {
[application registerForRemoteNotifications];
[manager handlePushRegisterForRemoteNotifications<span style="color: #333333">:</span>notificationSettings];

}

6. Implemente o método **didRegisterForRemoteNotificationsWithDeviceToken**:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    
    [manager handlePushRegistration:deviceToken];
    
    if(userInfoNotification!=nil) {
        [manager handlePushReceived:userInfoNotification];
        
    }
}

7. Implemente o método **didFailToRegisterForRemoteNotificationsWithError**:

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    
    NSLog(@"Registration for remote notification failed with error: %@", error.localizedDescription);
    [manager handlePushRegistrationFailure:error];
}

8. Adicione a implementação do método **didReceiveRemoteNotification**:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    
    [manager handlePushReceived:userInfo];

}

Geolocalização

📘

Esta configuração é opcional. Todavia, não adicionar o trecho abaixo impedirá a realização de campanhas de push geolocalizadas.

9. No arquivo Info.plist adicione as seguintes chaves: **NSLocationAlwaysUsageDescription** e **NSLocationWhenInUseUsageDescription**.

<?xml version="1.0" encoding="UTF-8"?><plist version="1.0">
<dict>
	<key>NSLocationAlwaysUsageDescription</key>
	<string>Precisamos de sua localização para uma oferta direcionada</string>
	<key>NSLocationWhenInUseUsageDescription</key>
	<string>Precisamos de sua localização para uma oferta direcionada</string>
</dict>
</plist>

10. No arquivo **ViewController.h** adicione a importação das seguintes bibliotecas:

#import <CoreLocation/CoreLocation.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import "PushNotificationManager.h"

11. No arquivo **ViewController.h** adicione na interface ViewController uma extensão da classe **CLLocationManagerDelegate** e a variável **locationManager**.

@interface ViewController : UIViewController<CLLocationManagerDelegate>{
    
    CLLocationManager * locationManager;
    
}@end

12. No arquivo **ViewController.m** adicione a seguinte implementação no corpo do método **viewDidLoad**:

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    locationManager =[[CLLocationManager alloc]init];
    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8) {
        
        [locationManager requestWhenInUseAuthorization];
    }
    
    PushNotificationManager *pushNotificationManager  = [PushNotificationManager sharedInstance];
    
    
    if ( [CLLocationManager authorizationStatus]) {
        [pushNotificationManager handleUpdateLocations:locationManager];
    }
}

🚧

Alteração Build Options

Antes de fazer a compilação, altere a propriedade Enable Bitcode no Build Settings do target do seu app para No.

1696

📘

Código Fonte

O projeto exemplo utilizado neste guia se encontra disponível em nosso Github.
Fique a vontade para dar um Fork em nosso repositório 😃
https://github.com/inngage/inngage-objectivec-sample