objective c - Facebook iOS SDK 4.1.0 Share Callback -
using fbsdk mentioned in title of question, present simple share dialog in view controller:
// setup content share fbsdksharelinkcontent *content = [[fbsdksharelinkcontent alloc] init]; content.contenturl = linkurl; content.contentdescription = description; content.contenttitle = title; content.imageurl = imageurl; // show share dialog [fbsdksharedialog showfromviewcontroller:controller withcontent:content delegate:somedelegate];
and implement delegate method...
- (void)sharer:(id<fbsdksharing>)sharer didcompletewithresults:(nsdictionary *)results { nslog(@"sweet, shared."); }
so far good, long user has facebook application installed on device. issue arises when user not have facebook installed. if case, safari opens web version of facebook's login flow (this fine), if switch original application without logging facebook / performing additional tasks, completion delegate method shown above called.
does have experience workaround this? seems there should reliable way determining whether or not post did indeed occur.
note: above code pretty pseudo-ish. in actual implementation have indeed implemented of delegate call backs (didcomplete, didcancel, , didfail).
edit: turns out, results dictionary empty when completion method called if facebook app installed on device. overcome this, check needs done see if facebook installed first.
of course after posting stumbled upon answer. results dictionary returned in didcompletewithresults method contains postid key if share occurred. logic simple as:
- (void)sharer:(id<fbsdksharing>)sharer didcompletewithresults:(nsdictionary *)results { nsurl *fburl = [nsurl urlwithstring:@"fb://"]; if (![[uiapplication sharedapplication] canopenurl:fburl]) if (results[@"postid"]) { nslog(@"sweet, shared, , facebook isn't installed."); } else { nslog(@"the post didn't complete, switched app"); } } else { nslog(@"sweet, shared, , facebook installed."); } }
although works, doesn't seem safe way of going things (what if facebook changes key "postid" else in future? unlikely point).
Comments
Post a Comment