ios6 - iPhone:Upload image on Instagram -
i have written code upload image on instagram follows:
cgrect rect = cgrectmake(20 ,20 , 200, 200); uigraphicsbeginimagecontextwithoptions(self.view.bounds.size, self.view.opaque, 0.0); [self.view.layer renderincontext:uigraphicsgetcurrentcontext()]; uigraphicsendimagecontext(); nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory,nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring *jpgpath = [documentsdirectory stringbyappendingpathcomponent:@"after2sm.ig"]; nsstring *fileurl = [nsstring stringwithformat:@"file://%@",jpgpath]; nsurl *igimagehookfile = [nsurl fileurlwithpath:fileurl]; self.dic.uti = @"com.instagram.photo"; self.dic = [self setupcontrollerwithurl:igimagehookfile usingdelegate:self]; self.dic=[uidocumentinteractioncontroller interactioncontrollerwithurl:igimagehookfile]; [nsdictionary dictionarywithobject:@"my caption" forkey:@"instagramcaption"]; [self.dic presentopeninmenufromrect:rect inview:self.view animated:yes];
but opens actionsheet "instagram" option when click on nothing happens..can please me
try , in code set image in imgupload object
- (ibaction)instagrambuttonclick { cgrect rect = cgrectmake(0.0, 0.0, 612, 612); uigraphicsbeginimagecontext(rect.size); [imgupload drawinrect:rect]; uiimage *img = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); nsstring *savepath = [nshomedirectory() stringbyappendingpathcomponent:@"documents/test.igo"]; [uiimagejpegrepresentation(img, 1.0) writetofile:savepath atomically:yes]; nsurl *igimagehookfile = [[nsurl alloc] initwithstring:[[nsstring alloc] initwithformat:@"file://%@", savepath]]; self.dic.uti = @"com.instagram.photo"; self.dic = [self setupcontrollerwithurl:igimagehookfile usingdelegate:self]; self.dic=[uidocumentinteractioncontroller interactioncontrollerwithurl:igimagehookfile]; self.dic.annotation = [nsdictionary dictionarywithobject:@"your message" forkey:@"instagramcaption"]; [self.dic presentopeninmenufromrect: cgrectzero inview: self.view animated: yes ]; }
//add delegate uidocumentinteractioncontrollerdelegate
, following delegate method
- (uidocumentinteractioncontroller *) setupcontrollerwithurl: (nsurl*) fileurl usingdelegate: (id <uidocumentinteractioncontrollerdelegate>) interactiondelegate { uidocumentinteractioncontroller *interactioncontroller = [uidocumentinteractioncontroller interactioncontrollerwithurl: fileurl]; interactioncontroller.delegate = interactiondelegate; return interactioncontroller; }
Comments
Post a Comment