Get ready
The following three frameworks are introduced first:
Messageui.framework
Social.framework
Accounts.framework
and introduce the following several header files where these methods are implemented
#import <MessageUI/MFMailComposeViewController.h>
#import <Social/Social.h>
#import <Accounts/Accounts.h>
Twitter and Facebook
where urlstr for me to share the URL string, you can pass the content you want to share
Twitter, facebook-(void) Shareurl: (NSString *) urlstr viaslframework: (NSString *) sltype{//only support Fecebook and T Witter if ([Sltype Isequaltostring:slservicetypefacebook] | | [Sltype Isequaltostring:slservicetypetwitter]) {if ([Slcomposeviewcontroller Isavailableforservicetype:slservicetypetwitter]) {Slcomposeviewco Ntroller *socialcomposer = [Slcomposeviewcontroller composeviewcontrollerforservicetype:sltype]; [Socialcomposer Addurl:[nsurl urlwithstring:urlstr]; [Socialcomposer setcompletionhandler:^ (slcomposeviewcontrollerresult result) {NSString *OUTSTR = [NSString new]; Switch (Result) {case slcomposeviewcontrollerresultcancelled:outstr = @ "Sharing failed! "; Break Case SLCOMPOSEVIEWCONTROLLERRESULTDONE:OUTSTR = @ "Sharing failed! "; Break Default Break } Uialertview *myalertview = [[Uialertview alloc]initwithtitle:nil Message:outstr Delegate:nil cancelbuttontitle:@ "OK" Otherbuttontitles:nil]; [Myalertview show]; }]; [Self presentviewcontroller:socialcomposer animated:yes completion:nil]; } }}
Copy Content to Clipboard
URL copy-(void) Pasteurl: (NSString *) url{ //Copy text uipasteboard *pasteboard = [Uipasteboard Generalpasteboard]; [Pasteboard Setstring:url]; Copy Picture/ * uipasteboard *pasteboard = [Uipasteboard Generalpasteboard]; [Pasteboard setdata:uiimagejpegrepresentation ([UIImage imagenamed:@ "Account_icon_friend.png"], 1.0) forpasteboardtype:@ "Public.jpeg"];*/ uialertview *alert = [[Uialertview alloc] Initwithtitle:nil message:@ " The content has been copied to the Clipboard "Delegate:self cancelbuttontitle:@" OK "otherbuttontitles:nil, nil]; [Alert show];}
Line
Where urlstr is what I want to share. Share for the text
line-(void) Sharewithline: (NSString *) urlstr{//share text NSString *contenttype = @ "text"; NSString *urlstring = [NSString stringwithformat:@ "line://msg/%@/%@", ContentType, [Urlstr stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]]; /****** share picture Uipasteboard *pasteboard = [Uipasteboard Generalpasteboard]; [Pasteboard setdata:uiimagejpegrepresentation ([UIImage imagenamed:@ "Account_icon_friend.png"], 1.0) forpasteboardtype:@ "Public.jpeg"]; NSString *contenttype = @ "image"; NSString *urlstring = [NSString stringwithformat:@ "line://msg/%@/%@", ContentType, Pasteboard.name]; Get the picture from the Clipboard, the text can also be like this */nsurl *url = [Nsurl urlwithstring:urlstring]; Lorwylog (@ "%@", url); if ([[[UIApplication sharedapplication] canopenurl:url]) {[[UIApplication sharedapplication] openurl:url]; } else{Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Prompt" message:@ "Invalid URL" delegate:self cancelbuttontitle:@ "OK" otherbuttontitles:nil, nil]; [Alert show]; }}
MAIL
URLSTR Mail content, kmailaddress as the destination email address
Ps:self needs to implement the Mfmailcomposeviewcontrollerdelegate protocol to send a message after calling the second method below
mail-(void) Shareurlmail: (NSString *) urlstr{ if ([Mfmailcomposeviewcontroller cansendmail]) { Mfmailcomposeviewcontroller *mailviewcontroller = [[Mfmailcomposeviewcontroller alloc] init]; [Mailviewcontroller setsubject:kmailaddress]; [Mailviewcontroller setmessagebody:urlstr Ishtml:no]; Mailviewcontroller.mailcomposedelegate = self; MailViewController.navigationBar.tintColor = [Uicolor blackcolor]; [Self Presentviewcontroller:mailviewcontroller animated:yes completion:nil];} -(void) Mailcomposecontroller: (Mfmailcomposeviewcontroller *) controller didfinishwithresult: (mfmailcomposeresult) Result Error: (Nserror *) error{ [self dismissviewcontrolleranimated:yes completion:nil];}