WhatsApp Sharing (Via URL Scheme)¶
Installation¶
As of release 3.0.3, WhatsApp is available as a Share option that can be easily enabled.
Since WhatsApp does not have a formal API/SDK, no app registration or access tokens are required. Instead, the WhatsApp URL Scheme (“whatsapp://”) is used to communicate between the Socialize SDK and WhatsApp.
Configuring WhatsApp in Socialize (SDK)¶
To enable WhatsApp sharing, simply enable it:
#pragma mark
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// set the socialize api key and secret, register your app here: http://www.getsocialize.com/apps/
[Socialize storeConsumerKey:@"SOCIALIZE_CONSUMER_KEY"];
[Socialize storeConsumerSecret:@"SOCIALIZE_CONSUMER_SECRET"];
[SZWhatsAppUtils setShowInShare:YES];
//your application specific code
return YES;
}
Note
The WhatsApp app must be installed on a device for WhatsApp sharing to display in the Share dialog. This functionality works on devices only, not in Simulator.
Note
Since WhatsApp uses URL Schemes to navigate from your app, there is no callback mechanism to return to your app from WhatsApp once the user has sent the share as a WhatsApp message. Users will be notified of this via a UIAlertView before navigating to WhatsApp.
Posting to WhatsApp on your own¶
Should you need to post to WhatsApp on your own, you can do so by using the direct WhatsApp access methods on the utils classes.
- (void)shareOnWhatsApp {
SZEntity* entity = [SZEntity entityWithKey:@"http://cs303404.vk.me/v303404440/1ae3/ZkKQLEFGeyY.jpg" name:@"Something"];
if ([SZWhatsAppUtils isAvailable]) {
[SZWhatsAppUtils shareViaWhatsAppWithViewController:self options:nil entity:entity success:^(id<SocializeShare> share) {
//your application specific code on success action
} failure:^(NSError *error) {
//your application specific code on failure action
}];
}
}