Facebook three ways to share

Source: Internet
Author: User

Sign up for the app at Facebook Developer Center to get the app ID  https://
second, import fbsdkcorekit.framework, Fbsdkloginkit.framework, Fbsdksharekit.framework Three, in the Info.plist file to add<key>CFBundleURLTypes</key><array> <dict> <key>CFBundleURLSchemes</key> < Array> <string>fb218334765200160</string> </array> </dict></array><key>FacebookAppID</key><string>218334765200160</string><key>FacebookDisplayName</key><string>airplane</string><key>LSApplicationQueriesSchemes</key><array> <string>fbapi</string> <string>fb-messenger-api</string> <string>fbauth2</string> <string>fbshareextension</string></array>Iv. setting up bundlesIDv. setting in Appdelegate#import<fbsdkcorekit/fbsdkcorekit.h>-(BOOL) Application: (UIApplication *) Application Didfinishlaunchingwithoptions :(Nsdictionary *) launchoptions {//Override point for customization after application launch.[[Fbsdkapplicationdelegate sharedinstance] Application:application Didfinishlaunchingw    Ithoptions:launchoptions]; returnYES;}- (void) Applicationdidbecomeactive: (UIApplication *) Application {[Fbsdkappevents Activateapp];}-(BOOL) Application: (UIApplication *) Application OpenURL: (Nsurl*) URL sourceapplication: (NSString*) sourceapplication annotation: (ID) Annotation {return[[Fbsdkapplicationdelegate sharedinstance] Application:application                                                       Openurl:url sourceapplication:sourceapplication Annotation:annotation];} Vi. settings in the controller#import "ViewController.h"#import<FBSDKShareKit/FBSDKShareKit.h>#import<Social/Social.h>#import "UIToastUtil.h"@interfaceViewcontroller () <FBSDKSharingDelegate>@property (nonatomic, strong) Slcomposeviewcontroller*Myslcomposersheet;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.}/** First call to Facebook client*/-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event{[self sharetofacebook];}/** There are Facebook clients*/- (void) sharetofacebook{fbsdksharelinkcontent*content1 =[[Fbsdksharelinkcontent alloc] init]; Content1.contenturl= [Nsurl urlwithstring:@"https://developers.facebook.com"]; Content1.contenttitle=@"I just share ."; //[Fbsdksharedialog showfromviewcontroller:self withcontent:content1 Delegate:nil]; //[Fbsdkmessagedialog showwithcontent:content1 delegate:nil];Fbsdksharedialog *dialog =[[Fbsdksharedialog alloc] init]; Dialog.fromviewcontroller=Self ; dialog.Delegate=Self ;    [Dialog Setsharecontent:content1]; Dialog.mode=fbsdksharedialogmodenative; [Dialog show];}#pragmaMark-fbshare delegate-(void) Sharer: (ID<FBSDKSharing>) Sharer didcompletewithresults: (Nsdictionary *) results{NSLog (@"---> Have a Facebook client to share successfully! ");}- (void) Sharer: (ID<FBSDKSharing>) Sharer Didfailwitherror: (Nserror *) error{NSLog (@"---> Sharing failed! , %@", error); if(error==nil| | [[NSNullNULL] Isequal:error]) {/** No Facebook client, check whether the phone is bound account*/[self sharefacebook]; }}- (void) Sharerdidcancel: (ID<FBSDKSharing>) sharer{NSLog (@"---> Cancel sharing! ");}- (void) sharefacebook{if([[[[[[Uidevice Currentdevice] systemversion] Substringtoindex:1] Intvalue]>=6){        if([Slcomposeviewcontroller Isavailableforservicetype:slservicetypefacebook]) {Self.myslcomposersheet=[Slcomposeviewcontroller Composeviewcontrollerforservicetype:slservicetypefacebook]; //[Self.myslcomposersheet setInitialText:self.productDetailModel.productName];//Product Name//Nsurl *imageurl = [Nsurl URLWithString:self.productDetailModel.primaryThumbimage]; //NSData *imagedata = [NSData Datawithcontentsofurl:imageurl]; //[Self.myslcomposersheet addimage:[uiimage imagewithdata:imagedata scale:1];//Product Map[Self.myslcomposersheet addurl:[nsurl urlwithstring:@"https://developers.facebook.com"]];//Product Address[self presentViewController:self.mySLComposerSheet animated:yes completion:nil];        [Mbprogresshud HideHUDForView:self.view Animated:yes]; }Else{/** No client is installed, and the phone does not have a binding account, use the Web share*/[self sharewithweb]; } [Self.myslcomposersheet Setcompletionhandler:^(slcomposeviewcontrollerresult result) {NSString*output; Switch(Result) { CaseSlcomposeviewcontrollerresultcancelled:output=@"Click Cancel Share";  Break;  CaseSlcomposeviewcontrollerresultdone:output=@"Click to share";  Break; default:                     Break; }            if(Result =slcomposeviewcontrollerresultcancelled)) {                //[Uitoastutil showToast:self.view message:@ "You are not install Facebook app."];//Uialertview *alert = [[Uialertview alloc] initwithtitle:mblocalizedstring (kfacebookmessage) Message:ou                Tput delegate:nil cancelbuttontitle:mblocalizedstring (Kfacebookok) Otherbuttontitles:nil]; //[alert show];            }        }]; }}/** There is no Facebook client, Facebook is not tied to the account, use the Web share*/- (void) sharewithweb{fbsdksharelinkcontent*content =[[Fbsdksharelinkcontent alloc] init]; Content1.contenturl= [Nsurl urlwithstring:@"https://developers.facebook.com"]; Content1.contenttitle[Email protected] "This is sharing";Fbsdksharedialog *dialog =[[Fbsdksharedialog alloc] init]; Dialog.fromviewcontroller=Self ; dialog.Delegate=Self ;    [Dialog setsharecontent:content]; Dialog.mode=Fbsdksharedialogmodeweb; [Dialog show];}

Facebook three ways to share

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.