Adding date and image fields in PodioKit for Objective-C (iOS)
I'm trying to add some data to a new item before saving it. I'm getting errors when I try to add a date/time, and when I try to add an image. I'm not sure what the correct syntax for it is as I don't think it has been documented yet. Currently I have
[PKTFile uploadWithData:signaturePNG fileName:fileNameString mimeType:@"image/png" completion:^(PKTFile *file, NSError *error) {
if (!error) {
PKTItem *visitor = [PKTItem itemForAppWithID:1234567];
visitor[@"name"] = nameField.text;
visitor[@"organisation"] = orgField.text;
visitor[@"contact"] = contactField.text;
visitor[@"time"] = @{@"start": startTime};
visitor[@"signature"] = file.fileId;
[visitor saveWithCompletion:^(PKTResponse *response, NSError *error) {
if (!error) {
NSLog(@"Uploaded!");
} else {
NSLog(@"Save error");
NSLog(@"%@", error);
}
}];
} else {
NSLog(@"Upload error");
NSLog(@"%@", error);
}
}];
but this is giving me an error: Terminating app due to uncaught exception 'InvalidFieldValueException', reason: 'Invalid field value: (null)'
This error occurs for both the time or signature field - as soon as I take them both out, it works fine.
If I change the signature line from file.fileID
to file
, it gives this huge error:
Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: bad request (400)" UserInfo=0x17dacb10 {NSErrorFailingURLKey=https://api.podio.com/item/app/1234567/, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x17ecfc90> { URL: https://api.podio.com/item/app/1234567/ } { status code: 400, headers {
Connection = "keep-alive";
"Content-Length" = 534;
"Content-Type" = "application/json; charset=utf-8";
Date = "Fri, 16 May 2014 07:01:39 GMT";
Server = nginx;
"X-Podio-Request-Id" = ehz7a9my;
"X-Rate-Limit-Limit" = 250;
"X-Rate-Limit-Remaining" = 247;
} }, NSLocalizedDescription=Request failed: bad request (400)}
Any idea what the correct syntax for inserting dates and images is? Clearly I'm doing something very wrong!
-
Official comment
Hi Jonathan!
Great to see you trying out the new version of PodioKit. As we are still developing it and improving it on a daily basis, I would suggest you to point directly to the Github repo by using this line in your Podfile:
pod 'PodioKit', :git => "https://github.com/podio/podio-objc.git"
To answer your question, I've updated the README in the Github repository to describe the acceptable values for the various field types.
Basically, if you have an image field, just set the value to be the PKTFile object you get back from the upload operation. For dates, use an instance of the PKTDateRange class. This means you don't have to use the file ids directly to set field values. PodioKit will figure it out from the PKTFile object. I will also add a bit more detail to the exception message, as it is quite unclear right now.
Let us know if you run into any other bugs or issues.
Comment actions -
So I'm passing in the file returned from
uploadWithData:fileName:mimeType:completion:
and it's giving me that Bad Request 400 error I mentioned in my original question. Any idea why this is happening? The file is coming straight out of the upload function, I haven't changed anything about it.
Please sign in to leave a comment.
Comments
5 comments