Skip to content

Chat SDK iOS: Settings configuration

simonsmiley64 edited this page Apr 13, 2017 · 3 revisions

When adding modifications to the Chat SDK it is important to ensure that fixes are applied to the entire framework and not just added to the code. This especially applies to the Chat SDK settings which could easily be applied with small code fixes but which should instead be added to enable easy modification. In this wiki we will be looking at modifications made to the Chat SDK and added to its settings. We will be looking at their functionality and also the effect they have one the code.

App Badge Notifications

Function: Apps in iOS can have notification numbers associated with them. The Chat SDK modifies this value depending on the number of private messages are unread. Developers should be able to enable/disable this functionality in the app settings plist.

Setting the value: Set the app_badge_enabled BOOL in the project plist to YES or NO. This will turn on or off the app badge being set by the number of unread messages.

Code changes: The code for this is currently set in the BAppTabBarController.m. The function -(void) setBadge: (int) badge allows you to set the app tab bar badge value. At the end of this function we check whether the user has enabled the app badge then set the badge or not:

    if ([BSettingsManager appBadgeEnabled]) {
        [UIApplication sharedApplication].applicationIconBadgeNumber = badge;
    }

User Chat Information

Function: The chat view controller allows you a large amount of control over the users in the chat. You can enable your users to see other users talking as well as access their profiles. There is also much scope for adding chat moderators and admins from the BUsersViewController. This functionality might not be needed in an app meaning we have added a way to disable this.

Setting the value: Set the user_chat_info_enabled BOOL in the project plist to YES or NO. This will turn on or off users being able to open the BUsersViewController.

Code changes: There are two parts where the code needed to be modified for this change. The first is that if the functionality is enabled we let the users know with a subtitle in the navigation bar:

    if ([BSettingsManager userChatInfoEnabled]) {
        [self setSubtitle:[NSBundle t: bTapHereForContactInfo]];
    }

The next is to disable tapping the navigation bar in the first place. We change this in the ElmChatViewController for a number of reasons. Firstly, this view is very flexible and is used by our BChatViewController2, were we to change the child view then the changes wouldn't be applied to all our different chat controllers. Secondly, we might decide to enable this functionality from somewhere else. If we were to use this to check whether the chat would load the UsersView then we might have problems further down the line.

    if ([BSettingsManager userChatInfoEnabled]) {
            UITapGestureRecognizer * titleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(navigationBarTapped)];
        [self.navigationItem.titleView addGestureRecognizer:titleTapRecognizer];
    }