Skip to content

Working with Activity Feed Posts

Post your first activity

To post an activity to global activity feed you can use code below:

  1. Create GetSocialActivityPostContent object:

    1
    2
    3
    4
    5
    GetSocialActivityPostContent *postContent = [GetSocialActivityPostContent new];
    postContent.text            = @"Hello, this is my first post!";
    postContent.buttonTitle     = @"Get extra life!";
    postContent.buttonAction    = @"get-extra-life";
    postContent.image           = [UIImage imageNamed:...]; // load image here
    

    Recommended Image Size

    Recommended image resolution is 1024x768px. Bigger images will be downscaled.

  2. Post an activity to Global Feed:

    1
    2
    3
    4
    5
    6
    [GetSocial postActivityToGlobalFeed:postContent
                                success:^(GetSocialActivityPost *post) {
                                    NSLog(@"Successfully posted an activity.");
                                } failure:^(NSError *error) {
                NSLog(@"Failed to post an activity, error: %@", error);
            }];
    

Custom Activity Feed

To post an activity to custom feed, just pass feed name as a parameter to postActivityToFeed method:

1
[GetSocial postActivity:content toFeed:@"level-42" success:successBlock failure:failureBlock];

Action Buttons

Action button can be added to your activity or announcement. It is a simple, but very powerful part of Activity Feed functionality. See how to post activity with button:

  1. Create post content with Action Button:

    1
    2
    3
    4
    GetSocialActivityPostContent *contentWithButton = [GetSocialActivityPostContent new];
    contentWithButton.text            = @"Look at my cool profile!";
    contentWithButton.buttonTitle     = @"Look now!";
    contentWithButton.buttonAction    = @"look-profile";
    
  2. Post to a selected feed:

    1
    [GetSocial postActivityToGlobalFeed:contentWithButton success:successBlock failure:failureBlock];
    

In this case you will post as a user.
If you want to post as an App, use dashboard - simple activity, or post an Announcement.

Field Type Value
buttonTitle String A text that will be displayed on button
buttonAction String Your internal action, that you know how to deal with. Our SDK doesn’t know anything about your actions, we just attach them to buttons.

If you don’t use GetSocial UI, you should display and handle your button with own code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
- (void)showActionButton:(GetSocialActivityPost *)post {
    if (post.buttonTitle) {
        //show button
        [actionButton setTitle:post.buttonTitle forState:UIControlStateNormal];
        actionButton.tag = [self.posts indexOfObject:post];
        UITapGestureRecognizer *actionButtonTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didClickActionButton:)];
        actionButtonTap.numberOfTapsRequired = 1;
        [actionButton addGestureRecognizer:actionButtonTap];
    } else {
        //hide button
    }
}

- (void)didClickActionButton:(UITapGestureRecognizer *)sender {
    GetSocialActivityPost *postContent = self.posts[sender.view.tag];
    // Handle your action on button click.
    // [self processAction:postContent.buttonAction withPost:postContent];
}

If you’re using GetSocial UI, you life is easier, all you need is set ActivityButtonActionHandler:

1
2
3
4
5
6
GetSocialUIActivityFeedView *activityFeedView = [GetSocialUI createGlobalActivityFeedView];
[activityFeedView setActionButtonHandler:^(NSString *action, GetSocialActivityPost *post) {
    // Handle your action on button click.
    // [self processAction:action withPost:post];
}];
[activityFeedView show];

Example of your processAction method:

1
2
3
4
5
6
7
- (void)processAction:(NSString *)action withPost:(GetSocialActivityPost *)post {
    if ([action isEqualToString:@"look-profile"]) {
        [self showUserProfile:post.author];
    } else if ([action isEqualToString:@"try-campaign-mode"]) {
        [self startCampaignMode];
    }
}

Post Activity With Mentions

To mention user in the Activity Feed post insert @12345678, where 12345678 is the GetSocial user Id you want to mention:

1
2
3
4
5
GetSocialPublicUser user = ...;
NSString *contentText = [NSString stringWithFormat:@"Hello, @%@. How are you?", user.userId];
GetSocialActivityPostContent *postContent = [GetSocialActivityPostContent new];
postContent.text = contentText;
[GetSocial postActivityToGlobalFeed:postContent success:success failure:failure];

To mention the application use "@app" in the post text:

1
2
3
4
GetSocialActivityPostContent *postContent = [GetSocialActivityPostContent new];
postContent.text = @"Hey, @app. When new features will be available?";

[GetSocial postActivityToGlobalFeed:postContent success:success failure:failure];

On the backend, when activity is posted, @id is replaced with the display name of the user or app name.

To check if activity has any mentions in content, use post.mentions method. Mention object contains id of user, start and end index of mention in content text, so you can handle interactions with mentions.

If you’re using GetSocial UI, to handle click on mention in Activity Feed, use MentionClickHandler:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
GetSocialUIActivityFeedView *activityFeed = [GetSocialUi createGlobalActivityFeedView];
[activityFeed setMentionClickHandler:^(NSString *mention) {
    if ([mention isEqualToString:GetSocialUI_Shortcut_App])
        // Handle click on the app mention
    } else {
        NSString *userId = mention;
        // Handle click on the user mention
    }
}];
[activityFeed show];

Post Activity With Tags

To post activity with tag, just insert #mytag - where mytag is a tag you want to post:

1
2
3
4
GetSocialActivityPostContent *postContent = [GetSocialActivityPostContent new];
postContent.text = @"Like my #cat photo!";

[GetSocial postActivityToGlobalFeed:postContent success:success failure:failure];

Tags may go one by one without spaces:

1
NSString *contentText = @"#get#social with your friends!"

The activity with text as above will have two tags #get and #social.

Warning

Tag should contain at least one letter, consist of letters, numbers and _, and be not longer than 80 symbols, otherwise it won’t be treated as tag on the backend side.

If you’re using GetSocial UI, to handle click on the tag use TagClickHandler:

1
2
3
4
5
GetSocialUIActivityFeedView *activityFeed = [GetSocialUi createGlobalActivityFeedView];
[activityFeed setTagClickHandler:^(NSString *tag) {
    [self handleTagClick:tag];
}];
[activityFeed show];

For example, on tag click you can open Activity Feed filtered by that tag using setFilterByTags as described below.

Post from GetSocial UI

On the list of posts, there is an input to post something. Only text posts are supported from GetSocial UI, to post images or buttons from SDK, use code above.

List Activities

To get a list of posted activities in global feed:

1
2
3
4
5
6
7
8
GetSocialActivitiesQuery *query = [GetSocialActivitiesQuery postsForGlobalFeed];
[GetSocial activitiesWithQuery:query
                       success:^(NSArray<GetSocialActivityPost *> *activities) {
                           NSLog(@"Successfully retrieved activities.");
                           [self showActivities:activities];
                       } failure:^(NSError *error) {
            NSLog(@"Failed to get activities, error: %@", error);
        }];

Pagination

ActivitiesQuery class supports pagination. By default, it retrieves first posts with limit=10.
Fox example, if you have a list of activities and want to get 15 older activities:

1
2
3
4
GetSocialActivityPost *oldestActivity = [self.posts lastObject];
GetSocialActivitiesQuery *query = [GetSocialActivitiesQuery postsForGlobalFeed];
[query setLimit:15];
[query setFilter:ActivitiesBefore activityId:oldestActivity.activityId];

In the same way you can get newer activities, using GetSocialActivitiesFilter.ActivitiesAfter:

1
2
3
4
GetSocialActivityPost *newestActivity = [self.posts firstObject];
GetSocialActivitiesQuery *query = [GetSocialActivitiesQuery postsForGlobalFeed];
[query setLimit:15];
[query setFilter:ActivitiesAfter activityId:newestActivity.activityId];

Filter By User

GetSocialActivitiesQuery class allows you to query activities posted by provided user. By default, it retrieves all activities.
For example, to get activities posted by current user:

1
2
3
GetSocialId userId = [GetSocialUser userId];
GetSocialActivitiesQuery *query = [GetSocialActivitiesQuery postsForGlobalFeed];
[query setFilterByUser:userId];

Friends Feed

You can ask to give you activities in feed, that were posted by you and your friends:

1
2
GetSocialActivitiesQuery *query = [GetSocialActivitiesQuery postsForGlobalFeed];
[query setIsFriendsFeed:YES];

Posts With Tags

You can filter all activities by tags, so you will have only activities that contain at least one tag from provided list:

1
2
GetSocialActivitiesQuery *query = [GetSocialActivitiesQuery postsForGlobalFeed];
[query setTags:@[@"cat", @"dog", @"animal"]];

Open GetSocial Global Activity Feed View

GetSocialUI Library provides convenient way to show Activity Feed with all needed UI with a very little code execution:

1
2
3
4
5
6
GetSocialUIActivityFeedView *activityFeedView = [GetSocialUI createGlobalActivityFeedView];
[activityFeedView setActionButtonHandler:^(NSString *action, GetSocialActivityPost *post) {
    NSLog(@"Action button was pressed with action: %@", action);
}];
BOOL wasShown = [activityFeedView show];
NSLog(@"Get Social Activity Feed UI was shown: %@", wasShown ? @"YES" : @"NO");

You will see the similar view on the screen:


GetSocial Activity Feed View

If you want to customize Activity Feed view, see UI Customization.

Also, read more about GetSocial UI.

Custom Activity Feed

Custom activity feed is automatically created by SDK, so you don’t need to check does it exist or create it manually. Just use it:

  1. To open GetSocial Activity Feed View:

    1
    [[GetSocialUI createActivityFeedView:@"level-42"] show];
    
  2. To create a query for custom feed activities:

    1
    GetSocialActivitiesQuery *query = [GetSocialActivitiesQuery postsForFeed:@"level-42"];
    

Feed name restrictions

Feed name could contain only alphanumeric symbols: letters [a-z], numbers [0-9], -, _, .; and should be not longer than 64 symbols.

User Avatar Click Handler

If you want to handle avatar click while using GetSocial UI, you can set AvatarClickListener when you’re creating view:

1
2
3
4
5
GetSocialUIActivityFeedView *view = [GetSocialUI createGlobalActivityFeedView];
[view setAvatarClickHandler:^(GetSocialPublicUser *user) {
    [self handleAvatarClick:user];
}];
[view show];

For example, on avatar click you could:

  • Open user profile;
  • Suggest to add a user to friends;
  • Show some in-game information for a user;
  • Send a message for a user, etc.

Handler is not invoked on application avatar click

AvatarClickHandler is invoked only by click on the user avatar, not application one. Reach us via Intercom or support@getsocial.im if you need this functionality.

Activity Feed View For User

You can specify an user ID to show activity feed with only his posts.
For example, to show activity feed of current user:

1
2
3
4
GetSocialId userId = [GetSocialUser userId];
GetSocialUIActivityFeedView *view = [GetSocialUI createGlobalActivityFeedView];
[view setFilterByUser:userId];
[view show];

Friends Feed View

You can show Friends Activity Feed, that contains activities posted by you and your friends. To do that, simply set showFriendsFeed to YES:

1
2
3
GetSocialUIActivityFeedView *view = [GetSocialUI createGlobalActivityFeedView];
[view setShowFriendsFeed:YES];
[view show];

Read-only Activity Feed View

If you want to hide controls, that allows user to post, comment, like or dislike activities, you can use Read-only feed feature:

1
2
3
4
BOOL readOnlyFeed = YES;
GetSocialUIActivityFeedView *view = [GetSocialUI createGlobalActivityFeedView];
[view setReadOnly:readOnlyFeed];
[view show];

Also, you can restrict user from doing some actions with UiActionHandler.

Activity Feed View Filtered By Tags

You can show Activity Feed with activities that contain at least one tag from provided list:

1
2
3
GetSocialUIActivityFeedView *view = [GetSocialUI createGlobalActivityFeedView];
[view setFilterByTags:@[@"cat", @"cats", @"kitten"]];
[view show];

Give us your feedback! Was this article helpful?

😀 🙁