iOS App Inbox

 

The inbox services will allow you to persist notifications you send to a user in an inbox in the App. It also allows you to send messages to users who have not opted into push notifications as these messages come into the inbox like a feed when the app is opened. You are also not constrained by the push notification format and can use a richer style in your inbox messages.

 

Integration guides for Objective-C and Swift based Apps below. Note: Make sure you have setup the inbox on the platform before you start, this is a prerequisite.  

 

Enabling the Inbox - Objective-C

In the standard integration described in the iOS integration guide The inbox is switched off.  It can be turned on using the setInboxEnabled method. In your iOS App where you have initialised xtremepush in the app delegate. Add:

[XPush setInboxEnabled:YES];

Before

[XPush applicationDidFinishLaunchingWithOptions:launchOptions];

As shown below:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

// ... 
[XPush setInboxEnabled:YES];
// ...
[XPush applicationDidFinishLaunchingWithOptions:launchOptions]; return YES; }

 

 

You will also need to add a UI element (Button) to launch the inbox. When tapped this button will open the inbox. You may for example use a notification icon like a Bell on your menu bar.

 

 

Wherever you are handling your interactions with this button you can open the inbox with the following method:

[XPush openInbox];

 

Add Badging

If you want your icon to display a badge when a user has new messages in the inbox since the last time it was opened see below, there is a an xtremepush button type that can be used for this XPInboxButton.

 

To implement badging simply make the button you use for notification an XPInboxButton, for example:

Create your button element

XPInboxButton *button = [[XPInboxButton alloc] init];

 

Configure the button. XPInboxButton inherits from UIButton, so you can deal with it just like with UIButton.

So can set the size and the image:

[button setFrame:CGRectMake(0, 0, 24, 24)];
[button setImage:someImage forState:UIControlStateNormal];

XPInboxButton has a few helpers to quickly change badge color:

// set badge background color default is red
- (void)setBadgeColor:(UIColor *)color;

// set color of the text used for number on badge default is white
- (void)setBadgeTextColor:(UIColor *)color;

You can make the badge blue for example:

[button setBadgeColor: [UIColor redColor]];

You can also access badge element itself which is just a UILabel object

[button.badge setAnyUILabelAttribute:...]

When ready add the button to a view. For example as a navigation bar item:

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:nil action:nil];
>barButton.customView = button;
self.navigationItem.leftBarButtonItem = barButton;

Or in any other way, such as:

[someView addSubview: button];

 

Enabling the Inbox - Swift

In the standard integration described in the iOS integration guide The inbox is switched off.  It can be turned on using the setInboxEnabled method. In your iOS App where you have initialised xtremepush in the app delegate. Add:

XPush.setInboxEnabled(true)

Before

XPush.applicationDidFinishLaunchingWithOptions(launchOptions);

As shown below:

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
 
        
        //Start - Initialise XPush
        //...
        XPush.setInboxEnabled(true)
XPush.registerForRemoteNotificationTypes(NotificationSettings.getNotificationSettings()) XPush.applicationDidFinishLaunchingWithOptions(launchOptions) //End - Initialise XPush
 

You will also need to add a UI element (Button) to launch the inbox. When tapped this button will open the inbox. You may for example use a notification icon like a Bell on your menu bar.

 

 

Wherever you are handling your interactions with this button you can open the inbox with the following method:

XPush.openInbox();

 

Add Badging

If you want your icon to display a badge when a user has new messages in the inbox since the last time it was opened see below, there is a an xtremepush button type that can be used for this XPInboxButton.

 

 

To implement badging simply make the button you use for notification an XPInboxButton, for example:

Create your button element for example if you use a storyboard you may set the Custom class to be XPInboxButton: 

 

And when added to your code it will look like: 

@IBOutlet weak var InboxButton: XPInboxButton!

 

Configure the button to your required look, XPInboxButton inherits from UIButton, so you can deal with it just like with a UIButton to set the size, image etc.

XPInboxButton also has a few helpers to quickly change badge color:


// set badge background color default is red
// setting custom blue here:
InboxButton.setBadgeColor(UIColor.init(red: 0.114, green: 0.525, blue: 0.784, alpha: 1))
        
// set color of the text used for number on badge default is white
// setting dark grey here
InboxButton.setBadgeTextColor(UIColor.darkGrayColor())

 

You can also access badge element itself which is just a UILabel object and you can for example move the badge so it fits better with your image


//For example move badge to be inset by 5px from top right of image
InboxButton.imageEdgeInsets = UIEdgeInsetsMake(5, 0, 0, 5)
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.