Using a Custom Share UI

If you have your own custom implementation of a share UI you can still benefit from the Loopy™ social analytics platform by creating a trackable URL to be shared, and notifying the analytics platform when the share was successful.

Simply use the [SZAPIClient shortlink:withCallback:] method to create a trackable URL for sharing when the user executes a share. Then, once sharing is complete, ensure you call [SZAPIClient reportShare:withCallback:] to record the share.

This can be implemented as follows:

- (void)shortenAndShareWithCustomUI:(NSString *)url {
    
    //init this and begin its session elsewhere
    STAPIClient *apiClient;
    
    NSArray *tags = [NSArray arrayWithObjects:@"tag1", @"tag2", nil];
    STShortlink *shortlinkObj = [apiClient shortlinkWithURL:@"www.UrlToShorten.com" title:nil meta:nil tags:tags];
    [apiClient shortlink:shortlinkObj
                 success:^(AFHTTPRequestOperation *operation, id responseObject) {
                     
                     //use the shortlink in the activity dialog
                     NSDictionary *responseDict = (NSDictionary *)responseObject;
                     NSString *shortlink = (NSString *)[responseDict valueForKey:@"shortlink"];
                     NSArray *activityItems = @[shortlink];
                     
                     //assumes you have a custom activity, though you can use the Loopy STFacebookActivity and STTwitterActivity as well
                     MyCustomActivity *activity = [[MyCustomActivity alloc] init];
                     [activity prepareWithActivityItems:activityItems];

                     //Your custom UI sharing code goes here
                     //...
                     
                     //when your custom UI receives notification of a successful share, call this:
                     [[NSNotificationCenter defaultCenter] postNotificationName:LoopyShareDidComplete object:activity];

                     //if user cancels before sharing in your custom UI, call this:
                     [[NSNotificationCenter defaultCenter] postNotificationName:LoopyShareDidCancel object:activity];

                     //Assuming share is called and is successful, call this to record with Loopy:
                     STShare *shareObj = [apiClient reportShareWithShortlink:shortlink
                                                                     channel:activity.activityType];
                     [apiClient reportShare:shareObj
                                    success:^(AFHTTPRequestOperation *operation, id responseObject) {
                                        [[NSNotificationCenter defaultCenter] postNotificationName:LoopyRecordShareDidSucceed object:responseObject];
                                    }
                                    failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                        [[NSNotificationCenter defaultCenter] postNotificationName:LoopyRecordShareDidFail object:error];
                                    }];
                 }
                 failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                     //any failure handling
                 }];
}