How do I upload image Podio SDK using Objective-C (iOS)? - ios

I am integrating the Podio SDK. I am getting all data item values and updating also, but images won't upload. Any idea? I don't know how to upload an image on Podio SDK.
NSData *data = UIImageJPEGRepresentation(self.ImgView_Sign.image, 0.8f);
[[[PKTFile uploadWithData:data fileName:#"mobi.jpg"] pipe:^PKTAsyncTask *(PKTFile *file){
PKTItem *item = [PKTItem itemForAppWithID:431525395];
item[#"title"] = #"CHEKRI";
item[#"signautre"] = file;
return [item save];
}] onSuccess:^(PKTItem *item){
NSLog(#"PKT FILE is %#",item);
} onError:^(NSError *error){
NSLog(#"Error file %#",error);
}];

Please use below code might be work for you.
UIImage *image = [UIImage imageNamed:#"some-image.jpg"];
NSData *data = UIImageJPEGRepresentation(image, 0.8f);
PKTAsyncTask *uploadTask = [PKTFile uploadWithData:data fileName:#"image.jpg"];
[uploadTask onComplete:^(PKTFile *file, NSError *error) {
if (!error) {
NSLog(#"File uploaded with ID: %#", #(file.fileID));
}
}];

Adding an image to an image field is a two-step process.
First you must upload the file. https://developers.podio.com/doc/files/upload-file-1004361 will give you a file object with a file_id you need in step two.
Step two is to create a new item, update an item or update the field value. Here you pass the file_id as a the value for the field.
We have a general tutorial on working with items here https://developers.podio.com/examples/items
Working with file_ids for image fields is not different than the other field types. Just as you use profile_ids to work with Contact fields you use file_ids to work with image fields.
Original source: https://help.podio.com/hc/en-us/community/posts/200516608-API-image-upload-to-Image-Field

Related

Creating an image from NSData and saving it using PHPhotoLibrary

I am tring to create an image using the NSData collected from Bluetooth. The data is saved in NSData variable recdata which is then converted to image using imageWithData. I am trying to save this image to the Photo library using the code below. But I don't see the image in the photo library. Am I missing something??
Also, as I am doing this project where I am receiving the data from bluetooth, I don't know how to check the error message on my iPhone screen. Currently, I am using the [information setText:[NSString stringWithFormat:#"%#", error.localizedFailureReason ]]; from the completionhandler to print the error message. But nothing gets printed and the app crashes and closes down.
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
//PHAssetResourceType assetType = PHAssetResourceTypePhoto;
UIImage *image = [UIImage imageWithData:recdata];
[PHAssetChangeRequest creationRequestForAssetFromImage: image];
[information setText:[NSString stringWithFormat:#"Krishna"]];
//PHAssetCreationRequest *request = [PHAssetCreationRequest creationRequestForAssetFromImage: image];
//PHAssetResourceCreationOptions *creationOptions = nil;
//creationOptions.originalFilename = command1; // Name of the file to be taken from command1
//[request addResourceWithType:assetType data:rxdata options:creationOptions]; //rxdata has all the data needed for the file to be transferred to the final image file.
} completionHandler:^(BOOL success, NSError *error) {
[information setText:[NSString stringWithFormat:#"%#", error.localizedFailureReason ]];
}];

Updating Plist file via download iOS

I've got a quiz app on the Apple app store. The questions are stored in a Plist file. What I'm looking to do is find a way to update the Plist file via downloading a new version and not having to submit an update every time I have new questions to add
Does anyone know of a decent tutorial which may help me?
Many thanks.
I'm not sure about tutorials, but the steps to achieve what you describe are pretty simple:
Create a url request to your remote data
Parse the returned data
Write the parsed data to a new local plist
Eg:
// Create a NSURL to your data
NSString *dataPath = #"www.mydata.com/path";
NSURL *dataURL = [NSURL URLWithString:dataPath];
// Create an asycnhronous request along with a block to be executed when complete
[NSURLConnection sendAsynchronousRequest:[[NSURLRequest alloc] initWithURL:dataURL]
queue:[[NSOperationQueue alloc] init]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
if (error) {
NSLog(#"%#", error.localizedDescription);
// Handle the request error
}
else {
// We have some data, now we need to serialize it so that it's usable
NSError *serializationError;
NSDictionary *serializedDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&serializationError];
if (serializationError) {
NSLog(#"%#", serializationError.localizedDescription);
// Handle the serialization error
}
else {
// We have a serialized NSDictionary, now we just want to write it
// First we create the path to write it to, eg. uers documents directory
NSURL *documentsDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
// Then write it
BOOL success = [serializedDictionary writeToFile:documentsDirectory.path atomically:YES];
if (!success) {
NSLog(#"Error writing file");
}
}
}
}];
Note: You may want to think about storing your data in a remote database like Parse. This way you can query for new questions and only download those so you're not using unnecessary bandwidth. You may also want to consider using Core Data to maintain your local data rather than writing it to a plist. The main advantage being that you don't have to serialise the entire plist into memory to use it - you can just query for the particular questions you need.
Hope this helps.

How Do I save the user's image fetched from fbprofilepictureview using the Facebook SDK

So I'm implementing the Facebook login button in an iOS app I'm currently working on, I'm trying to save the user's profile picture that's accessed using this line;
self.profilePicture.profileID = user.id;
I haven't had any luck storing that image for use elsewhere in the app. I have tried a number of methods including this approach
imageUrl=[NSString stringWithFormat:#"https://graph.facebook.com/%#/picture?redirect=true", user.username];
Any help is welcome!
You need to use user.objectID and not user.username.
You can also use my drop-in replacement for FBProfilePictureView, DBFBProfilePictureView. This exposes the imageView as a readonly property. Using that, your code would be something like this...
self.profilePicture.completionHandler = ^(DBFBProfilePictureView* view, NSError* error){
if(error) {
view.showEmptyImage = YES;
NSLog(#"Loading profile picture failed with error: %#", error);
} else {
UIImage *image = view.imageView.image;
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:filename atomically:NO];
}
};

When I receive my data, I save it to Core Data and start downloading the images. How do I link downloaded images to their Core Data counterparts?

I call an API which then gives me a bunch of posts from the website. Each post contains a title, description and a thumbnail. I save the title and description and start the download of the image, but I'm confused how I then link up the image once downloaded with the object in Core Data it responded to.
I then have a UITableView with a NSFetchedResultsController that populates the table view with the Core Data objects.
for (WebServicePost *post in NSArray *posts) {
Post *newPost = [NSEntityDescription insertNewObjectForEntityForName:#"Post" inManagedObjectContext:self.managedObjectContext];
newPost.title = post.title;
newPost.info = post.info;
NSURLSessionDataTask *imageDataTask = [self.downloadSession dataTaskWithURL:[post.URL imgurThumbnailURLWithSize:CSImgurThumbnailSizeSmall] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
UIImage *downloadedImage = [UIImage imageWithData:data];
--> // What do I do here?
}];
[imageDataTask resume];
}
NSError *coreDataError;
if (![self.managedObjectContext save:&coreDataError]) {
NSLog(#"%#", [error localizedDescription]);
}
I'm confused how I link the downloaded image to a cell in the table view.
My plan was to have an NSCache that mapped the indexPath of each cell to the corresponding UIImage, but at this point I don't know the indexPath of the cell. I can't call indexPathForObject: either, as it hasn't been saved to Core Data yet.
I then considered mapping the Post object itself to the UIImage, instead of the indexPath, but this made my fearful as if the Post object changes, the one I had a reference to will no longer work, as it's the initial Post object.
Then in cellForRowAtIndexPath: I'd check if there was an image, if so I'd use it, if not I'd just continue waiting for it.
I'm confused how to match this up properly though. Is my setup wrong?
Before you start your for loop, make sure you add this line:
NSMutableArray *cellData = [NSMutableArray array];
Then in the "What do I do here part" type this code:
NSMutableDictionary *postData = [[NSMutableDictionary alloc] init];
[postData setObject:post forKey:#"post"];
[postData setObject:downloadedImage forKey:#"image"];
[cellData addObject:[postData copy]];
Now you can cycle through your cellData, and every image will be matched up with its post data because they are being pointed to through a dictionary!
So to get a post and it's image you could do this:
NSDictionary *data = [postData objectAtIndex:1];
[data objectForKey:#"post"]; //will return your post data for post in index 1
[data objectForKey:#"image"]; //will return your image for post in index 1

iOS - Is it possible to rename image file name before saving it into iPhone device gallery from app?

Hey I'm new to iPhone and I have been trying to make an gallery kind of app. Basically, what I want to do is that i need to save all the captured images into a specific folder like a new album "My_App Images" related to our app name in iPhone device gallery, it's working for me, but I am having trouble to change the image file name, i don't know that Is it possible to specify a file name? Using iPhoto, currently i am getting image file name as "IMG_0094.jpg", can we change it with any other file name like "Anyfilename.png" format programmatically?
here is my code for saving images to the specific album :
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[self.library saveImage:image toAlbum:#"My_App Images" withCompletionBlock:^(NSError *error) {
if (error!=nil) {
NSLog(#"Image saving error: %#", [error description]);
}
}];
[picker dismissViewControllerAnimated:NO completion:nil];
}
Any source or link for reference is appreciated. Thanks for the help!
There is a way to kinda do that, by setting the image IPTC metadata field "Object Name". If you later import the image to iPhoto, then this name will be used as its title.
See details (and code) at http://ootips.org/yonat/how-to-set-the-image-name-when-saving-to-the-camera-roll/ .
Do you meant,
// Build NSData in memory from the btnImage...
NSData* imageData = UIImageJPEGRepresentation(image, 1.0);
// Save to the default Apple (Camera Roll) folder.
[imageData writeToFile:#"/private/var/mobile/Media/DCIM/100APPLE/customImageFilename.jpg" atomically:NO];
Now adjust the path of folder as per your folder name...
Sorry to disappoint you, but it seems that you can not change the name of the photos, before or after saving, in the photo album, custom or not. Here is a post to explain it:
iOS rename/delete albums of photos
Edit
So, to clarify my comment, use the following override:
Download the NSMutableDictionary category for metadata of image here.
Also download the sample project CustomAlbumDemo from here and modify the NSMutableDictionary+ImageMetadata.m file in the CustomAlbumDemo project as:
-(void)saveImage:(UIImage*)image toAlbum:(NSString*)albumName withCompletionBlock:(SaveImageCompletion)completionBlock
{
//write the image data to the assets library (camera roll)
NSData* imageData = UIImageJPEGRepresentation(image, 1.0);
NSMutableDictionary *metadata = [[NSMutableDictionary alloc] init];
[metadata setDescription:#"This is my special image"];
[self writeImageDataToSavedPhotosAlbum:imageData metadata:metadata completionBlock:^(NSURL *assetURL, NSError *error) {
//error handling
if (error!=nil) {
completionBlock(error);
return;
}
//add the asset to the custom photo album
[self addAssetURL: assetURL
toAlbum:albumName
withCompletionBlock:completionBlock];
}];
}

Resources