Push Story Setup

The Push Story feature requires UNNotification Framework and iOS 10. The feature is only available from iOS SDK version 3.2.1.

Step 1: Enable Push In Your App

Please follow The Push notification Integration to enable push in your app.

Step 2: Adding the Notification Content Extension Target

In your app project, go to menu “File”->”New”->”Target…”, add a new “Notification Content Extension” target and activate it.

Add Content Extension

Xcode should generate a new target for you and create files automatically for you including:

  • NotificationViewController.h
  • NotificationViewController.m
  • MainInterface.storyboard

Step 3: Enable Capacities

The Background Mode in the Capabilities section of the main app target is required by the Push Story feature. After turn on the background modes, select “Background fetch” and “Remote Notification”.

Enable Background Mode

You also need to add Capability App Groups. If you haven’t had any app group in your app, go the the Capability of the main app target, turn on the App Groups and click the “+”. Use your App’s bundle ID to create the App Group. For example, if your app’s bundle ID is com.company.appname, you can name your App Group group.com.company.appname.xyz. You need to turn on the App Groups for both the main app target and the content extension target.

Add App Groups

Step 4: Updating the Podfile

Add the following line to your Podfile:

1
2
3
target 'YourContentExtensionTarget' do
  pod 'Appboy-Push-Story', '~>3.0'
end

After updating the Podfile, navigate to the directory of your Xcode app project within your terminal and run pod install

Step 5: Link the Braze Push Story Framework

Click on + button and add New Copy Files Phase. Inside the new phase, change the destination to “Frameworks”. Add the AppboyPushStory.framework in the new phase (it can be found by clicking on Add Other... and navigating to the Pods folder).

New Copy File Phase

Add Framework

Go to the “Embedded Binaries” of the main application target and verify that AppboyPushStory.framework has been added.

Embedded Binaries

Click on + button and add New Run Script Phase. Make sure the newly created Run Script section is the last step in the Build Phases list. Add this text into the Script body:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"

find "$APP_PATH" -name 'AppboyPushStory.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"

FRAMEWORK_TMP_PATH="$FRAMEWORK_EXECUTABLE_PATH-tmp"

case "${TARGET_BUILD_DIR}" in
*"iphonesimulator")
;;
*)
if $(lipo "$FRAMEWORK_EXECUTABLE_PATH" -verify_arch "i386") ; then
lipo -output "$FRAMEWORK_TMP_PATH" -remove "i386" "$FRAMEWORK_EXECUTABLE_PATH"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_TMP_PATH" "$FRAMEWORK_EXECUTABLE_PATH"
fi
if $(lipo "$FRAMEWORK_EXECUTABLE_PATH" -verify_arch "x86_64") ; then
lipo -output "$FRAMEWORK_TMP_PATH" -remove "x86_64" "$FRAMEWORK_EXECUTABLE_PATH"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_TMP_PATH" "$FRAMEWORK_EXECUTABLE_PATH"
fi
;;
esac

done

Run Script

Go to the General tab of the content extension and add AppboyPushStory.framework in the Linked Frameworks and Libraries section.

Linked Frameworks

Step 6: Updating your Notification View Controller

In your NotificationViewController.h, add following lines to add new properites and import the header files:

1
#import <AppboyPushStory/AppboyPushStory.h>
1
2
@property (nonatomic) IBOutlet ABKStoriesView *storiesView;
@property (nonatomic) ABKStoriesViewDataSource *dataSource;

In your NotificationViewController.m, remove the default implementation and add following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
@implementation NotificationViewController

- (void)didReceiveNotification:(UNNotification *)notification {
  self.dataSource = [[ABKStoriesViewDataSource alloc] initWithNotification:notification
                                                               storiesView:self.storiesView
                                                                  appGroup:@"YOUR-APP-GROUP"];
}

- (void)didReceiveNotificationResponse:(UNNotificationResponse *)response
                     completionHandler:(void (^)(UNNotificationContentExtensionResponseOption option))completion {
  UNNotificationContentExtensionResponseOption option = [self.dataSource didReceiveNotificationResponse:response];
  completion(option);
}

- (void)viewWillDisappear:(BOOL)animated {
  [self.dataSource viewWillDisappear];
  [super viewWillDisappear:animated];
}

@end

Step 7: Set the Notification Content Extension Storyboard

  • Open the Notification Content Extension storyboard and place a new UIView in the notification view controller. Rename the class to ABKStoriesView. Make the view width and height autoresizable matching the Notification View Controller main view frame.

View Class

View Size

  • Link the Notification View Controller’s storiesView IBOutlet to the added ABKStoriesView.

View Outlet

Step 8: Set the Notification Content Extension Plist

Open the Info.plist file of the Notification Content Extension and add/change following keys under NSExtension \ NSExtensionAttributes:

UNNotificationExtensionCategory = ab_cat_push_story (String type) UNNotificationExtensionDefaultContentHidden = YES (Boolean type) UNNotificationExtensionInitialContentSizeRatio = 0.65 (Number type)

Plist Settings

Step 9: Updating the Braze Integration in Your Main App

Add ABKPushStoryAppGroupKey in the appboyOption dictionary as following when you initialize Braze:

1
2
3
4
5
6
NSMutableDictionary *appboyOptions = [NSMutableDictionary dictionary];
appboyOptions[ABKPushStoryAppGroupKey] = @"YOUR_APP_GROUP";
[Appboy startWithApiKey:@"YOUR_APPBOY_API_KEY"
          inApplication:application
      withLaunchOptions:launchOptions
      withAppboyOptions:appboyOptions];
WAS THIS PAGE HELPFUL?