1.facebook, Twitter, etc.
With the iphone's own sharing, first import social.framework, and then import
#import <Social/Social.h> End With the following code to complete the share:
Slcomposeviewcontroller *COMPOSEVC = [Slcomposeviewcontroller composeviewcontrollerforservicetype:sharedname];
BOOL success = [COMPOSEVC setinitialtext:self.sharedcontent];//share content
BOOL imagesuccess = [COMPOSEVC addimage:self.sharedimage];//share picture
Callback
Slcomposeviewcontrollercompletionhandler Myblock = ^ (Slcomposeviewcontrollerresult result) {
if (result = = slcomposeviewcontrollerresultcancelled) {
NSLog (@ "cancelled");
}else{
NSLog (@ "Post");
}
[Composevc Dismissviewcontrolleranimated:yes Completion:nil];
};
Composevc.completionhandler = Myblock;
if (Success && imagesuccess)
[Self PRESENTVIEWCONTROLLER:COMPOSEVC animated:yes completion:nil]; }
2.Instagram a little trouble, through the Uidocumentinteractioncontroller to complete the sharing, first of all, we must first determine whether the existence of Instagram, if there is a sharing of the operation. The code is as follows:
-(void) Instagramshare: (uiview*) view{
uiimage* image = [UIImage imagenamed:@ "csh.jpg"];//shared pictures
CGFloat cropval = (Image.size.height > image.size.width? image.size.width:image.size.height);
Cropval *= [Image scale];
CGRect croprect = (cgrect) {. Size.Height = Cropval,. size.width = Cropval};
Cgimageref imageref = Cgimagecreatewithimageinrect ([Image cgimage], croprect);
NSData *imagedata = uiimagejpegrepresentation ([uiimage imagewithcgimage:imageref], 1.0);
Cgimagerelease (IMAGEREF);
NSString *writepath = [Nstemporarydirectory () stringbyappendingpathcomponent:@ "Instagram.igo"];
if (![ ImageData Writetofile:writepath Atomically:yes]) {
Failure
NSLog (@ "image save failed to path%@", Writepath);
Return
} else {
Success.
}
Send it to Instagram.
Nsurl *fileurl = [Nsurl Fileurlwithpath:writepath];
Self.documentcontroller = [Uidocumentinteractioncontroller Interactioncontrollerwithurl:fileurl];
Self.documentController.delegate = self;
[Self.documentcontroller setuti:@ "Com.instagram.exclusivegram"];
[Self.documentcontroller setannotation:@{@ "instagramcaption": @ "My Love Dyl"}];
CGRect rect = CGRectMake (0, 0, 0, 0);
Uigraphicsbeginimagecontextwithoptions (View.bounds.size, View.opaque, 0.0);
[View.layer Renderincontext:uigraphicsgetcurrentcontext ()];
Uigraphicsendimagecontext ();
[Self.documentcontroller presentopeninmenufromrect:rect Inview:view Animated:yes];
}