Common Instructions

📘

Objective

Complete the Bubbl Plugin implementation with the common steps for both manual and Cocoapods integration.

📘

Audience

iOS App Developer

Common instructions for both Manual and Cocopods installation methods

Prepare Capabilities

Select your project in the navigation pane:

266

Then select your projects target:

1490

Background Modes

For Bubbl to work correctly the following Background Modes need to be enabled.

If you do not currently have Background Modes enabled click the + Capability button.

972

And select Background Mode.

546

The following Background Modes need to be enabled:

1646

Enable Push Notifications

Click the + Capability button again if you do not currently have Push Notifications enabled.

1836

Enable App Group

To enable App Groups, click the ‘+ Capability’ button in the toolbar and add “App Groups”

1842

Click the ‘+’ button under App Groups to add a new app group:

1274 882

It is recommended to give it a name starting with “group.” followed by the bundle identifier of your application and suffixed with “.bubbl”. This App Group will be required for setting up the plugin.

Include Frameworks

Select your project in the navigation pane and select the General tab:

1904

And add the following 3 Core Frameworks by clicking on the + button.

1336 1484

Add a Notification Service Extension

For Bubbl to perform most of the important features such as displaying media within notifications, showing badges to indicate unread notifications, adding Call to Action buttons or reporting notifications as delivered we must have a notification extension present in your application.

To create a notification extension add a new Target using the File menu:

1522

Select Notification Service Extension:

1818

Add the Notification Service Extension. The name can be anything you would like, but ensure it is added to the correct project and embedded in the correct application:

1470

Upon clicking finish you should be prompted to activate the extension, click “Activate”

780

Under the Notification Extension settings ensure you add the “App Groups” capability, with the same App Group as your application:

966 542 1260

Under General you will need to add the Bubbl framework.

Do this by clicking the + on Frameworks and Libraries.

1876

Select Add Files...

416

Navigate up one level in the directly hierarchy.

492

And select Bubbl.xcframework

682

Change the Embed value from Embed & Sign to Do Not Embed

1468 1870

There should now be a few files added to your project for your notification extension, we need to modify these files. They may be either in Swift or Objective C depending on the language choice when setting up.

568

The Notification Service class that was just created should extends BUNotificationService extension:

#import <UserNotifications/UserNotifications.h>
#import <Bubbl/Bubbl.h>


@interface NotificationService : BUNotificationServiceExtension


@end

The class should register the App Group in the initializer:

@implementation NotificationService


// on init set the app group identifier in the base class
- (instancetype)init {
    self = [super init];
    if (self) {
        self.appGroupIdentifier = @"<APP GROUP HERE>";
    }
    return self;
}


@end
import UserNotifications
import Bubbl

class NotificationService: BUNotificationServiceExtension {
    override init() {
        super.init()
        setAppGroupIdentifier("<APP GROUP HERE>")
    }
}

📘

Troubleshooting

Ensure that the iOS deployment target is the same version as your application, otherwise the Notification Extension may not run on older devices.

Adding the Plugin

Your AppDelegate should be updated to setup the Bubbl plugin the didFinishLaunchingWithOptions method, and we also need to inform the plugin when a device token is received or notifications will be presented or responded:

Add the import for Bubbl to the AppDelegate.h so that it can be used in the AppDelegate.m class.

#import <Bubbl/Bubbl.h>
#import <Bubbl/Bubbl.h>

@interface AppDelegate () <UNUserNotificationCenterDelegate>

@end
  
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Provide the API key and the endpoint URL to connect to
    [BUMain setupWithKey:@"<YOUR API KEY>" withURLString:@"https://mobilegateway.bubbl.tech/api" withAppGroup: @"<APP GROUP HERE>"];
    
    // provide additional debugging information
    [BUMain sharedInstance].debugMode = YES;
    
    // register for notifications
    [application registerForRemoteNotifications];
    
    [UNUserNotificationCenter currentNotificationCenter].delegate = self;
    
    return YES;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
   [BUMain registerForRemoteNotificationsWithDeviceToken: deviceToken];
}

- (void) userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
    [[BUMain sharedInstance] userNotificationCenter:center willPresentNotification:notification withCompletionHandler: completionHandler];
}

- (void) userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
    [[BUMain sharedInstance] userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}

@end
import UIKit
import Bubbl

@main
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        // Provide the API key and the endpoint URL to connect to
        BUMain.setup(withKey: "<YOUR API KEY>", withURLString: "https://mobilegateway.bubbl.tech/api", withAppGroup: "<APP GROUP HERE>")
        
        // provide additional debugging information
        BUMain.sharedInstance().debugMode = true
        
        // register for notifications
        application.registerForRemoteNotifications()
        
        UNUserNotificationCenter.current().delegate = self
        
        return true
    }
    
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        BUMain.registerForRemoteNotifications(withDeviceToken: deviceToken)
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        BUMain.sharedInstance().userNotificationCenter(center, willPresent: notification, withCompletionHandler: completionHandler)
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        BUMain.sharedInstance().userNotificationCenter(center, didReceive: response, withCompletionHandler: completionHandler)
    }
}

Permissions descriptions

Your application's descriptions for the following permissions need to be updated with using XCode or by updating the Info.plist:

1416
...
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>Your message here</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>Your message here</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>Your message here</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>Your message here</string>
...

An example message could be something like To provide a tailored and personal service we need to have access to your location.