iosslcomposeviewcontroller

Is there any way to detect if a user actually pressed the Twitter/Facebook post button in app?


I am trying to give "bonus points" for users who either tweet my advertisement message or post my advertisement message on Facebook. How can I detect if...

1) The user actually pressed the post button (this way I can give them the bonus points in app)?

2) The user did not change any text in the message box (my advertisement)?

On a side note, is it possible to make the message box for these un-editable? Here is my code to actually present the message to post each:

- (IBAction)tweetButtonPressed:(id)sender
{
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
    {
        SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
        [tweetSheet setInitialText:@"My advertisement message goes here."];
        [self presentViewController:tweetSheet animated:YES completion:nil];
    }

    else
    {
        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:@"Twitter Connection Failed"
                                  message:@"Make sure your device has an internet connection and you are connected to Twitter through your iPhone settings."
                                  delegate:self
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil];
        [alertView show];
    }
}



- (IBAction)facebookPostButtonPressed:(id)sender
{
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
    {
        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        [controller setInitialText:@"My advertisement message goes here."];
        [self presentViewController:controller animated:YES completion:nil];
    }

    else
    {
        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:@"Facebook Connection Failed"
                                  message:@"Make sure your device has an internet connection and you are connected to Facebook through your iPhone settings."
                                  delegate:self
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil];
        [alertView show];
    }
}

Solution

  • You can use compliton hander to know if he press the post button, however you can't know what the content of the post. If you realy want to you need to implement facebook yourself than you can even check the privecy of the post. I say this because when a app ask me to post I always do it as "Private" so no one see but I still get the "Bonus".

    Apple Docs

    Possible values for the result parameter of the completionHandler property.
    
    Declaration
    OBJECTIVE-C
    typedef NS_ENUM (NSInteger,
       SLComposeViewControllerResult ) {
       SLComposeViewControllerResultCancelled,
       SLComposeViewControllerResultDone 
     };
    Constants
    SLComposeViewControllerResultCancelled
    The view controller is dismissed without sending the post. For example, the user selects Cancel or the account is not available.
    
    Available in iOS 6.0 and later.
    
    SLComposeViewControllerResultDone
    The view controller is dismissed and the message is being sent in the background. This occurs when the user selects Done.
    
    Available in iOS 6.0 and later.
    

    https://developer.apple.com/library/ios/documentation/NetworkingInternet/Reference/SLComposeViewController_Class/#//apple_ref/c/tdef/SLComposeViewControllerResult