my app let user take picture, , add overlay before saving it.
i'd let user share picture using whatever app able handle images (i.e : email, facebook, twitter...), intent on android.
i tried use uidocumentcontroller, doesn't show facebook or twitter in official gallery. makes app crashes after taking second picture.
is there simple way ? don't wan't use facebook sdk , on.
here when picture taken :
[stillimageoutput capturestillimageasynchronouslyfromconnection:videoconnection completionhandler: ^(cmsamplebufferref imagesamplebuffer, nserror *error) { if(!error){ //resize picture , add overlay uiimage *picture = [self imagefromsamplebuffer:imagesamplebuffer]; //custom code letting me save picture in specific album [self.library saveimage:picture toalbum:@"myapp" metadata:metadata withcompletionblock:^(nserror *error,nsurl* asseturl) { if (error!=nil) { nslog(@"big error: %@", [error description]); } else { nslog(@"image saved"); nsstring *path = [[nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) objectatindex:0] stringbyappendingpathcomponent:@"tmp.jpg"]; //only way use uidocumentcontroller save file @ known location nsdata* imagedata = uiimagejpegrepresentation(picture, 0.9f); [imagedata writetofile:path atomically:no]; nslog(@"%@",path); doccontroller.url = [nsurl fileurlwithpath:path]; // make app crash after second picture [doccontroller presentpreviewanimated:yes]; } }]; } else { nslog(@"%@",error); } }];
ios has inbuilt social sharing kit. can share images via email, facebook , twitter. using google+ , other social services need respective sdks.
1) facebook
slcomposeviewcontroller *controller = [slcomposeviewcontroller composeviewcontrollerforservicetype:slservicetypefacebook]; [controller setinitialtext:message]; [controller addimage:image]; [self presentviewcontroller:controller animated:yes completion:nil];
2) twitter replace slservicetypefacebook slservicetypetwitter.
3) email
mfmailcomposeviewcontroller *emailsharecontroller = [[mfmailcomposeviewcontroller alloc] init]; emailsharecontroller.mailcomposedelegate = self; [emailsharecontroller setsubject:@"share image"]; [emailsharecontroller setmessagebody:message ishtml:no]; [emailsharecontroller addattachmentdata:uiimagejpegrepresentation(image, 1) mimetype:@"image/jpeg" filename:@"your_image.jpeg"]; if (emailsharecontroller) [self presentviewcontroller:emailsharecontroller animated:yes completion:nil];
4) remember add social.framework project , following header files
#import <messageui/mfmailcomposeviewcontroller.h> #import <social/social.h> #import <mobilecoreservices/mobilecoreservices.h>
5) set view controller delegate of
mfmailcomposeviewcontrollerdelegate
dismiss mailviewcontroller once mail send-
- (void)mailcomposecontroller:(mfmailcomposeviewcontroller *)controller didfinishwithresult:(mfmailcomposeresult)result error:(nserror *)error { [self dismissviewcontrolleranimated:yes completion:nil]; }
Comments
Post a Comment