Best way to check if sharing via SLComposeViewController is successful with a limited (or no) Internet connection

322 views Asked by At

Apple's documentation is clear on using SLComposeViewController to provide sharing capabilites with other social networks such as Twitter and Facebook.

Typical code will use isAvailableForServiceType to verify if a particular service is available and then add a completion handler to the view controller where an SLComposeViewControllerResult can be checked for either SLComposeViewControllerResultCancelled or SLComposeViewControllerResultDone, which check if the user tapped on the 'Post' button or on the 'Cancel' button after the sharing view has been displayed.

The issue here is that if you use SLComposeViewControllerResultDone to validate that the user made the request, you don't actually check if it was successful such as when the user has limited or no connectivity.

I have tried with one of my apps to test this and have noticed that the SLComposeViewControllerResultDone constant is still valid even if airplane mode is turned on such that a request is not possible. What this means is that the user fills out the sharing view fields and taps on 'Post' and my success code executes even though I should really be checking to make sure that the post was indeed successful.

Currently, I figure that the best option is to check for an Internet connection using the standard Reachability options (as recommended here) and disable the sharing button if a connection is not available, but I'm not sure if this is the best solution as it doesn't account for a limited connection where the user can tap on 'Post' but the actual request is unsuccessful.

My question is what is the best method of detecting if a sharing request has successfully completed?

1

There are 1 answers

0
Aanabidden On

then you need to make sure that you do not write below line in didSelectPost

[self.extensionContext completeRequestReturningItems:nil completionHandler:nil];

and once you get success or fail based on that in the your request handler you can write above line, so your didSelectPost should be like :

- (void)didSelectPost {
    NSExtensionItem *inputItem = self.extensionContext.inputItems.firstObject;
    NSItemProvider *attachment = inputItem.attachments.firstObject;
    if ([attachment hasItemConformingToTypeIdentifier:@"public.url"])
    {
        //NSString *strLink = [attachement loadItemForTypeIdentifier:@"public.url" options:nil completionHandler:nil];
        [attachment loadItemForTypeIdentifier: @"public.url"
                                       options: nil
           // make your request here
        }];
    }
}