
AppboyKit (também conhecido como o SDK Objective-C) não é mais suportado e foi substituído pelo Swift SDK. Não receberá mais novos recursos, correções de bugs, atualizações de segurança ou suporte técnico—no entanto, o envio de mensagens e a análise de dados continuarão a funcionar normalmente. Para saber mais, veja Apresentando o Novo SDK Braze Swift.
Integração do push primer
Campanhas de push primer incentivam os usuários a ativar as notificações push no dispositivo para o seu app. Obter a permissão dos usuários para enviar mensagens diretamente para seus dispositivos pode ser complexo, mas nossos guias podem ajudar! Este guia mostra as etapas que os desenvolvedores devem seguir para integrar o push priming.
Etapa 1: Adicionar snippet no arquivo AppDelegate.m
Adicione a seguinte linha de código ao seu arquivo AppDelegate.m no lugar da integração padrão:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
if (@available(iOS 10.0, *)) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
if (settings.authorizationStatus != UNAuthorizationStatusNotDetermined) {
// authorization has already been requested, need to follow usual steps
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) {
[[Appboy sharedInstance] pushAuthorizationFromUserNotificationCenter:granted];
}];
center.delegate = self;
[center setNotificationCategories:[ABKPushUtils getAppboyUNNotificationCategorySet]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
}];
} else {
UIApplication *sharedApplication = [UIApplication sharedApplication];
UIUserNotificationSettings *notificationSettings = [sharedApplication currentUserNotificationSettings];
if (notificationSettings.types) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound) categories:[ABKPushUtils getAppboyUIUserNotificationCategorySet]];
[sharedApplication registerUserNotificationSettings:settings];
[sharedApplication registerForRemoteNotifications];
}
}
if #available(iOS 10, *) {
let center = UNUserNotificationCenter.current()
center.getNotificationSettings(completionHandler: { (settings) in
if settings.authorizationStatus != .notDetermined {
// authorization has already been requested, need to follow usual steps
center.requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
Appboy.sharedInstance()?.pushAuthorization(fromUserNotificationCenter: granted)
}
center.delegate = self as? UNUserNotificationCenterDelegate
center.setNotificationCategories(ABKPushUtils.getAppboyUNNotificationCategorySet())
UIApplication.shared.registerForRemoteNotifications()
}
})
} else {
let notificationSettiings = UIApplication.shared.currentUserNotificationSettings
if notificationSettiings?.types != nil {
let setting = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories:nil)
UIApplication.shared.registerUserNotificationSettings(setting)
UIApplication.shared.registerForRemoteNotifications()
}
}
Etapa 2: Adicionar o verificador de evento personalizado ao arquivo AppDelegate.m
O snippet de código a seguir verifica se um evento personalizado precisa ser disparado. Adicione a seguinte linha de código ao seu AppDelegate.m.
if (@available(iOS 10.0, *)) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
if (settings.authorizationStatus == UNAuthorizationStatusNotDetermined) {
// ...
// fire custom event
// ...
}
}];
} else {
UIUserNotificationSettings *notificationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (!notificationSettings.types) {
// …
// fire custom event
// ...
}
}
if #available(iOS 10, *) {
let center = UNUserNotificationCenter.current()
center.getNotificationSettings(completionHandler: { (settings) in
if settings.authorizationStatus == .notDetermined {
// ...
// fire custom event
// ...
}
})
} else {
let notificationSettiings = UIApplication.shared.currentUserNotificationSettings
if notificationSettiings?.types != nil {
// ...
// fire custom event
// ...
}
}
Etapa 3: Configurar um handler de deep link
Coloque o snippet de código a seguir dentro do seu código de tratamento de deep link. Você deve executar esse código de deep linking apenas para a mensagem no app de push primer.
Consulte personalização do tratamento de links para saber mais sobre deep linking.
// ...
// check that this deep link relates to the push prompt
// ...
if (@available(iOS 10.0, *)) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) {
[[Appboy sharedInstance] pushAuthorizationFromUserNotificationCenter:granted];
}];
center.delegate = self;
[center setNotificationCategories:[ABKPushUtils getAppboyUNNotificationCategorySet]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound) categories:[ABKPushUtils getAppboyUIUserNotificationCategorySet]];
UIApplication *sharedApplication = [UIApplication sharedApplication];
[sharedApplication registerUserNotificationSettings:settings];
[sharedApplication registerForRemoteNotifications];
}
// ...
// check that this deep link relates to the push prompt
// ...
if #available(iOS 10, *) {
let center = UNUserNotificationCenter.current()
center.delegate = self as? UNUserNotificationCenterDelegate
center.requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
Appboy.sharedInstance()?.pushAuthorization(fromUserNotificationCenter: granted)
}
UIApplication.shared.registerForRemoteNotifications()
} else {
let setting = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories:nil)
UIApplication.shared.registerUserNotificationSettings(setting)
UIApplication.shared.registerForRemoteNotifications()
}