iphone - IOS: Get NSData from Photos path -


i have array of image paths photos gallery. need publish photos via facebook app. i'm getting error 324, "requires upload file". think way i'm getting nsdata path wrong. help?

nsdata *imagedata = [nsdata datawithcontentsofurl:[nsurl urlwithstring: urlimages[i]]]; nsmutabledictionary *params = [nsmutabledictionary dictionarywithobjectsandkeys:                                messagetextview.text, @"message", imagedata, @"source", nil]; 

but when hard code image inside project, working

nsstring *filepath = [[nsbundle mainbundle] pathforresource:@"imag0386" oftype:@"jpg"]; nsdata *imagedata = [nsdata datawithcontentsoffile:filepath];     mosaicshareimages[i]]]; nsmutabledictionary *params = [nsmutabledictionary dictionarywithobjectsandkeys:                                messagetextview.text, @"message", imagedata, @"source", nil]; 

if trying access assets library urls (starts assets-library://) nsdata method datawithcontentsofurl: fail , return nil. method not have required permissions access image related asset url. read assets library need use alassetslibrary's

- (void)assetforurl:(nsurl *)asseturl          resultblock:(alassetslibraryassetforurlresultblock)resultblock          failureblock:(alassetslibraryaccessfailureblock)failureblock 

method. can see api takes blocks failure , success arguments. method asynchronous because user may need asked grant access data.

more api from apple docs

when asset requested, user may asked confirm application's access library; method, though, returns immediately. should perform whatever work want asset in resultblock. if user denies access application, or if no application allowed access data, failure block called.

how use api can found in answer here. https://stackoverflow.com/a/13523463/1407017

hope helps!


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -