Appearance
Push Notifications
Push messaging allows you to keep your users up-to-date and re-engage them with your app after periods of inactivity. Upshot.ai makes it simple to send push notifications through the Application Push Notification Service (APNS). Upshot.ai also supports pushing an activity along with the Push.
Overview
The Upshot iOS SDK provides comprehensive push notification capabilities:
- Rich Media Support - Images, videos, audio, and custom layouts
- Deep Linking - In-app navigation and content targeting
- Custom Actions - Interactive buttons
- APNS Integration - Native iOS push notification support
Configuration
iOS Configuration
- Configure your app for push notifications APNS
- Configure your push notifications in Upshot.ai by uploading your .p12 or .p8 file in the Dashboard under the Push Notifications section.
Basic Setup
Register for Push Notifications
objective-c
// Request push notification permissions
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound + UNAuthorizationOptionBadge)
completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted) {
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] registerForRemoteNotifications];
});
}
}];
swift
// Request push notification permissions
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
if granted {
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
}
Handle Device Token And Push Info
Configure AppDelegate methods to handle device tokens and push payloads:
objective-c
#import <UIKit/UIKit.h>
#import <UserNotifications/UNUserNotificationCenter.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>
@end
@implementation AppDelegate
// Send device token to Upshot
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *pushToken = [self hexadecimalStringFromData:deviceToken];
[self sendPushTokenToUpshot:pushToken]
}
// Handle remote notifications
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[self sendPushDetailsToUpshot: userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
// Handle notifications when app is in foreground (iOS 10+)
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionBadge);
}
// Handle notification tap (iOS 10+)
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler {
[self sendPushDetailsToUpshot: response.notification.request.content.userInfo];
completionHandler();
}
- (NSString *)hexadecimalStringFromData:(NSData *)data
{
NSUInteger dataLength = data.length;
if (dataLength == 0) {
return nil;
}
const unsigned char *dataBuffer = (const unsigned char *)data.bytes;
NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)];
for (int i = 0; i < dataLength; ++i) {
[hexString appendFormat:@"%02x", dataBuffer[i]];
}
return [hexString copy];
}
- (void)sendPushTokenToUpshot:(NSString *)token {
BKUserInfo *uf = [[BKUserInfo alloc] init];
BKExternalId *extId = [[BKExternalId alloc] init];
[extId setApnsID:token];
[uf setExternalId:extId];
[uf buildUserInfoWithCompletionBlock:nil];
[[BrandKinesis sharedInstance] dispatchEventsWithTimedEvents:YES completionBlock:^(BOOL dispatched) {
}];
}
- (void)sendPushDetailsToUpshot:(NSDictionary *)userInfo {
BrandKinesis *bk = [BrandKinesis sharedInstance];
[bk setDelegate:self];
[bk handlePushNotificationWithParams:userInfo withCompletionBlock:nil];
}
// The delegate will be triggered with push deep link information, regardless of the template used.
- (void)brandKinesisOnPushClickInfo:(NSDictionary *)payload {
}
@end
swift
import UIKit
import UserNotifications
import UpshotUtility
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
var window: UIWindow?
// Send device token to Upshot
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let token = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
sendPushTokenToUpshot(token: token)
}
// Handle remote notifications
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
sendPushDetailsToUpshot(userInfo)
completionHandler(.newData)
}
// Handle notifications when app is in foreground (iOS 10+)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .sound, .badge])
}
// Handle notification tap (iOS 10+)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
sendPushDetailsToUpshot(response.notification.request.content.userInfo)
completionHandler()
}
func sendPushTokenToUpshot(token: String) {
let userInfo = BKUserInfo.init()
let externalId = BKExternalId.init()
externalId.apnsID = token
userInfo.externalId = externalId
userInfo.build(completionBlock: nil)
}
func sendPushDetailsToUpshot(_ userInfo:[AnyHashable:Any]){
BrandKinesis.sharedInstance().delegate = self
BrandKinesis.sharedInstance().handlePushNotification(withParams: userInfo) { (error) in
}
}
// The delegate will be triggered with push deep link information, regardless of the template used.
func brandKinesisOnPushClickInfo(_ payload: [AnyHashable : Any]) {
}
}
iOS Integration
For complete iOS setup including AppDelegate configuration, rich notifications, and service extensions, see the dedicated iOS Integration Guide.
Best Practices
- Request permissions at appropriate time - Don't ask for push permissions immediately on app launch
- Handle token updates properly - Device tokens can change, so always update Upshot.ai with the latest token
- Implement deep linking - Use push payloads to navigate users to specific content
- Test all notification types - Test both simple text notifications and rich media notifications
- Handle foreground notifications - Configure how notifications appear when the app is active
- Validate push setup - Test with the Upshot.ai dashboard before going live
Testing and Debugging
- Use Upshot.ai Dashboard - Send test notifications from the dashboard
- Check Device Token - Verify the device token is properly sent to Upshot.ai
- Test Notification Types - Test both simple and rich notifications
- Debug Payload - Log notification payloads to understand the structure
- Validate Certificates - Ensure your APNS certificates are properly configured
Troubleshooting
Common Issues
Push Notifications Not Received:
- Check APNS certificate configuration
- Verify device token is properly sent
- Ensure proper notification permissions are granted
- Check network connectivity
Rich Notifications Not Working:
- Verify notification service/content extensions are properly configured
- Check App Group ID configuration
- Ensure proper framework linking
Notification Click Handling:
- Verify delegate methods are properly implemented
- Check payload structure for deep linking data
- Ensure proper navigation handling
For comprehensive troubleshooting, refer to our FAQ section
- Request permissions at appropriate time - Don't ask for push permissions immediately on app launch
- Handle token updates properly - Device tokens can change, so always update Upshot.ai with the latest token
- Implement deep linking - Use push payloads to navigate users to specific content
- Test all notification types - Test both simple text notifications and rich media notifications
- Handle foreground notifications - Configure how notifications appear when the app is active
- Validate push setup - Test with the Upshot.ai dashboard before going live
- Analytics not tracking: Ensure push payloads are being sent to Upshot.ai correctly