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
    6
    7
    8
    UIImage *postImage = ... ; //load image here
    GetSocialAction *action = [[[GetSocialActionBuilder alloc] initWithType:@"get-extra-life"] build];
    
    GetSocialActivityPostContent *postContent = [GetSocialActivityPostContent new];
    postContent.text            = @"Hello, this is my first post!";
    postContent.buttonTitle     = @"Get extra life!";
    postContent.action          = action;
    postContent.mediaAttachment = [GetSocialMediaAttachment image:postImage];
    
    1
    2
    3
    4
    5
    6
    7
    let action = GetSocialActionBuilder.init(type: GetSocialActionType.init("get-extra-life")).build()
    let postImage: UIImage = ... //load image here
    let postContent = GetSocialActivityPostContent()
    postContent.text = "Hello, this is my first post!"
    postContent.buttonTitle = "Get extra life!"
    postContent.action = action
    postContent.mediaAttachment = GetSocialMediaAttachment.image(postImage)
    

    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);
            }];
    
    1
    2
    3
    4
    5
    GetSocial.postActivity(toGlobalFeed: postContent, success: { post in
        print("Successfully posted an activity.")
    }, failure: { error in
        print("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];
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
    5
    6
    7
    GetSocialActionBuilder *builder = [[GetSocialActionBuilder alloc] initWithType:GetSocialActionOpenProfile];
    [builder addActionDataValue:[GetSocialUser userId] forKey:GetSocialActionDataKey_OpenProfile_UserId];
    GetSocialAction *action = [builder build];
    GetSocialActivityPostContent *contentWithButton = [GetSocialActivityPostContent new];
    contentWithButton.text            = @"Look at my cool profile!";
    contentWithButton.buttonTitle     = @"Look now!";
    contentWithButton.action          = action;
    
    1
    2
    3
    4
    5
    6
    7
    let builder = GetSocialActionBuilder.init(type: GetSocialActionType.openProfile)
    builder.addActionDataValue(GetSocialUser.userId(), withKey: GetSocialActionDataKey._OpenProfile_UserId.rawValue)
    let action = builder.build()
    let contentWithButton = GetSocialActivityPostContent()
    contentWithButton.text = "Look at my cool profile!"
    contentWithButton.buttonTitle = "Look now!"
    contentWithButton.action = action
    
  2. Post to a selected feed:

    1
    [GetSocial postActivityToGlobalFeed:contentWithButton success:successBlock failure:failureBlock];
    
    1
    GetSocial.postActivity(toGlobalFeed: 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.

Read how to create actions.

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.action withPost:postContent];
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
func showActionButton(_ post: GetSocialActivityPost?) {
    if post?.buttonTitle != nil {
        //show button
        actionButton.setTitle(post?.buttonTitle, for: .normal)
        if let aPost = post {
            actionButton.tag = posts.index(of: aPost)
        }
        let actionButtonTap = UITapGestureRecognizer(target: self, action: #selector(self.didClickActionButton(_:)))
        actionButtonTap.numberOfTapsRequired = 1
        actionButton.addGestureRecognizer(actionButtonTap)
    } else {
        //hide button
    }
}

@objc func didClickActionButton(_ sender: UITapGestureRecognizer?) {
    let postContent: GetSocialActivityPost? = posts[sender?.view?.tag ?? 0]
    // Handle your action on button click.
    // [self processAction:postContent.action withPost:postContent];
}

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

1
2
3
4
5
6
GetSocialUIActivityFeedView *activityFeedView = [GetSocialUI createGlobalActivityFeedView];
[activityFeedView setActionHandler:^BOOL(GetSocialAction *action) {
    // Handle you action on button click.
    return [self handleAction:action];
}];
[activityFeedView show];
1
2
3
4
5
var activityFeedView: GetSocialUIActivityFeedView = GetSocialUI.createGlobalActivityFeedView()
activityFeedView.setActionHandler { (action) -> Bool in
    return selt.handleAction(action)
}
activityFeedView.show()

Read how to handle actions.

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];
1
2
3
4
5
let user: GetSocialPublicUser? = ...
let contentText = "Hello, @\(user.userId). How are you?"
let postContent = GetSocialActivityPostContent()
postContent.text = contentText
GetSocial.postActivity(toGlobalFeed: 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];
1
2
3
4
let postContent = GetSocialActivityPostContent()
postContent.text = "Hey, @app. When new features will be available?"

GetSocial.postActivity(toGlobalFeed: 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];
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
let activityFeed: GetSocialUIActivityFeedView = GetSocialUi.createGlobalActivityFeedView()
activityFeed.setMentionClickHandler({ mention in
    if (mention == GetSocialUI_Shortcut_App) {
        // Handle click on the app mention
    } else {
        let 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];
1
2
3
4
let postContent = GetSocialActivityPostContent()
postContent.text = "Like my #cat photo!"

GetSocial.postActivity(toGlobalFeed: postContent, success: success, failure: failure)

Tags may go one by one without spaces:

1
NSString *contentText = @"#get#social with your friends!"
1
let 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];
1
2
3
4
5
let activityFeed: GetSocialUIActivityFeedView = GetSocialUI.createGlobalActivityFeedView()
activityFeed.setTagClickHandler({ tag in
    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);
        }];
1
2
3
4
5
6
7
let query = GetSocialActivitiesQuery.postsForGlobalFeed()
GetSocial.activities(with: query, success: { activities in
    print("Successfully retrieved activities.")
    self.showActivities(activities)
}, failure: { error in
    print("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];
1
2
3
4
let oldestActivity = posts.last as GetSocialActivityPost
let query = GetSocialActivitiesQuery.postsForGlobalFeed()
query.setLimit(15)
query.setFilter(GetSocialActivitiesFilter.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];
1
2
3
4
let newestActivity = posts.first as GetSocialActivityPost
let query = GetSocialActivitiesQuery.postsForGlobalFeed()
query.setLimit(15)
query.setFilter(GetSocialActivitiesFilter.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];
1
2
3
let userId: GetSocialId = GetSocialUser.userId()
let 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];
1
2
let query = GetSocialActivitiesQuery.postsForGlobalFeed()
query.setIsFriendsFeed(true)

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"]];
1
2
let 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");
1
2
3
4
5
6
let activityFeedView: GetSocialUIActivityFeedView = GetSocialUI.createGlobalActivityFeedView()
activityFeedView.setActionButtonHandler({ action, post in
    print("Action button was pressed with action: \(action ?? "")")
})
let wasShown: Bool = activityFeedView.show()
print("Get Social Activity Feed UI was shown: \(wasShown ?? false ? "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];
    
    1
    GetSocialUI.createActivityFeedView("level-42").show()
    
  2. To create a query for custom feed activities:

    1
    GetSocialActivitiesQuery *query = [GetSocialActivitiesQuery postsForFeed:@"level-42"];
    
    1
    let query = GetSocialActivitiesQuery.posts(forFeed: "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];
1
2
3
4
5
var view: GetSocialUIActivityFeedView = GetSocialUI.createGlobalActivityFeedView()
view.setAvatarClickHandler({ user in
    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];
1
2
3
4
let userId: GetSocialId = GetSocialUser.userId()
let view: GetSocialUIActivityFeedView = 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];
1
2
3
let view: GetSocialUIActivityFeedView = GetSocialUI.createGlobalActivityFeedView()
view.setShowFriendsFeed(true)
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];
1
2
3
4
let readOnlyFeed = true
let view: GetSocialUIActivityFeedView = 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];
1
2
3
var view: GetSocialUIActivityFeedView = GetSocialUI.createGlobalActivityFeedView()
view.setFilterByTags(["cat", "cats", "kitten"])
view.show()

Give us your feedback! Was this article helpful?

😀 🙁