iOS AWS DynamoDB can't run a request - ios

I've been struggling with connecting to the AWS DynamoDB with my iOS app. I am frustrated with the lack of tutorials/documentation on the DynamoDB (I guess it is still fairly new). But I ahve been trying to follow Amazon's User Preference Tutorial I am trying to just connect to the database and read something or write something but I am getting an exception thrown.
AmazonCredentials *creds;
creds = [creds initWithAccessKey:MY_ACCESS_KEY withSecretKey:MY_SECRET_KEY];
AmazonDynamoDBClient *ddb = [[AmazonDynamoDBClient alloc] initWithCredentials:creds];
DynamoDBGetItemRequest *request = [[DynamoDBGetItemRequest alloc]
initWithTableName:#"Users" andKey:[[DynamoDBKey alloc] initWithHashKeyElement:
[[DynamoDBAttributeValue alloc] initWithS:#"Chase"]]];
DynamoDBGetItemResponse *response = [ddb getItem:request]; //THROWING THE EXCEPTION HERE!
NSMutableDictionary *user = response.item;
NSLog(#"%#",user);
The output reads:
Terminating app due to uncaught exception 'AmazonServiceException', reason: ''
The only thing that I changed from what the tutorial has done is the way I set up my user credentials and the line that throws the exception, the tutorial has:
DynamoDBCreateTableResponse *response = [[AmazonClientManager ddb] getItem:request];
I couldn't find any AmazonClientManager class anywhere, but the AmazonDynamoDBClient class seems to have the same method, so I am assuming that it should work (this could very well be the assumption that is breaking my code). I don't know if Amazon still supports that class because I can't find it in any documentation either.
Also, before I get yelled at, I know that I shouldn't be handing out my own credentials in the app. I will change this later. I am just trying to get to a sanity state for now.

You need to change these lines
AmazonCredentials *creds;
creds = [creds initWithAccessKey:MY_ACCESS_KEY withSecretKey:MY_SECRET_KEY];
to this
AmazonCredentials *creds = [[AmazonCredentials alloc] initWithAccessKey:MY_ACCESS_KEY withSecretKey:MY_SECRET_KEY];
Also, AmazonClientManager is not a part of the SDK. It's a part of the sample app and returns an instance of AmazonDynamoDBClient. It's included in the sample project.

Related

Get NSString out of ENNoteContent with Evernote Cloud SDK 2.0

I am new to Evernote SDK development and am using the evernote cloud SDK 2.0 as recommended by Evernote.
However, I am having trouble to get the NSString content out of the ENNoteContent object. I have tried the followings from searching online but none seems to work with the cloud sdk as I guess they are all for the old version of Evernote SDK...
1 Using "convertENMLToHTML" method.
According to this and this, I could call convertENMLToHTML directly on an ENNoteContent object much like this convertENMLToHTML:note.content. However, in the cloud SDK, this resulted in an exception inside ENMLUtility that terminates the app because convertENMLToHTML is expecting an NSString as opposed to ENNoteContent and the first thing this function does is trying to call [enmlContent dataUsingEncoding:NSUTF8StringEncoding]] which caused the exception if enmlContent is a pointer to ENNoteContent but not a pointer to NSString.
2 Attempting to get _emml object out of the ENNoteContent object
This post has a quote of calling [note.content enml] but this again doesn't work with cloud sdk as object enml isn't defined in the interface.
Does anyone know how one can get an NSString out of ENNoteContent? I would expect this to be a very straightforward process but am surprised that I wasn't able to find anything that works for the Cloud SDK.
3 Using generateWebArchiveData method
Per Sash's answer below, I have also attempted to use the generateWebArchiveData method in the example from the cloud sdk. The code I have looks like this:
[[ENSession sharedSession] downloadNote:result.noteRef progress:^(CGFloat progress) {
} completion:^(ENNote *note, NSError *downloadNoteError) {
if (note) {
NSLog(#"%#", note.title);
[note generateWebArchiveData:^(NSData *data) {
NSString* strContent = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(#"test content %#", strContent);
}];
} else {
NSLog(#"Error downloading note contents %#", downloadNoteError);
}
}];
However, strContent outputs "null" for a note that I have verified with legitimate content.
As a temporary hack, we added #property (nonatomic, copy) NSString * emml;
in ENNoteContent.h and removed the same line in ENNoteContent.m to get around this for now.
You are close. Technique #1 above is what you want, but as you discovered the enml property is private in the "default" SDK. Import the "advanced" header and you'll have access to note.content.enml. That is a string, and you can send it to convertENMLtoHTML if you prefer an HTML representation.
Do note that there is no "plaintext" string content for an existing note. You'll always see it as markup, and if you want to get rid of the markup, doing so is beyond the scope of the SDK-- how to do that depends very much on what the content you're dealing with looks like.
You should check out their samples included with SDK, seems like
-[ENNote generateWebArchiveData:] will get you HTML NSData in the completion block
https://github.com/evernote/evernote-cloud-sdk-ios/blob/master/Getting_Started.md#downloading-and-displaying-an-existing-note might also help

AFNetworking 2 AFHTTPRequestOperation failure block stripping keys from error userInfo

I have just updated my app from AFNetworking 1.3.3 to 2.0.1, which required rewriting my network client that used to subclass AFHTTPClient.
I swapped out AFHTTPClient for AFHTTRequestOperationManager (I need to support iOS 6) and everything works fine apart from this:
The server gives me a JSON error string with the details of the error in:
error.userInfo.localizedRecoverySuggestion
However, this key (localizedRecoverySuggestion) is no longer in my NSError object.
Does anybody any idea how I can access it? Or what part of AFNetworking is stripping it out? The server is still sending it, it just doesn't make it as for as the error object in my POST: etc methods.
I've spent some time on this and I'm struggling to find where the issue is.
After a spot of debugging, it looks like the data takes the following path through AFNetworking:
AFURLConnectionManager connection:didReceiveData:
AFURLResponseSerialization validateResponse:data:error:
At which point it is thrown away.
So as a quick fix I just added an extra dictionary entry to that method where userInfo is created as follows:
NSLocalizedRecoverySuggestionErrorKey: [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]
This is obviously a complete hack, but if anyone could give a pointer on how to accomplish this correctly, I'd be very grateful.

Google Cloud Endpoints generated iOS Client not working

I have a python webservice running locally using GAE Python SDK 1.8.3. After annotating the API and generating iOS client classes using Google Cloud Endpoints Service Generator I'm trying to call a remote procedure using it.
If I test my api using API Explorer, everything works just fine.
When I call using the iOS client, the call is received by the webservice, however the request cannot be decoded correctly. This is my first time using the Endpoints API so I don't know what is wrong.
What seems to be happening is that my request object is being wrapped in a "resource" key in the query JSON. Now, when my webservice tries to decode it, it yields a warning saying "No variant found for unrecognized field: resource". And, as my object is wrapped inside this key, it is skipped and never decoded to a message.
When the call is made using the API Explorer the object is not wrapped, so everything works.
This is what I'm doing in my webservice:
#endpoints.method(SearchRequest,
ContactListResponse,
path='search', http_method='post',
name='api.search')
def search(self, request):
user = request.user
number = request.number
This is how I call it from iOS:
GTLMyAPIMessagesSearchRequest * request = [[GTLMyAPIMessagesSearchRequest alloc] init];
request.user = #"+552199881234";
request.number = #"+5521717171";
GTLQueryMyAPI *query = [GTLQueryMyAPI queryForApiSearchWithObject:request];
[service executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
GTLMyAPIMessagesContactListResponse* object,
NSError *error)
{
NSArray* contacts = object.contacts;
}
Am I doing anything incredibly wrong here?
This is an annoying bug from iOS to Endpoints for local testing. I hope they fix it soon. :)
BTW instead of modifying QGTQueryMyAPI.m (which is a generated file). I do Theo's fix just after I create the query instead. So all of my queries that send data look like this (and I set that one flag to switch from localhost to deployed in other places too).
GTLQueryMyApi *query = [GTLQueryMyApi queryForSearchWithObject:someGtlObject];
if (LOCAL_HOST_TESTING) {
[query setJSON:someGtlObject.JSON];
}
This is not a great solution but a patch for now. I have the same problem when doing iOS endpoints localhost testing. However when I use the deployed backend I remove this line and everything is fine.
auth.shouldAuthorizeAllRequests = YES;
The "resource" key wrapping issue only happens when I add the line above to use localhost. So this morning I'm not using localhost, just the deployed version. Let me know if you fix the issue. :) Obviously pointing to the deployed version is not preferred for testing.
Alright! user2697002's answer showed me that this works when the webservice is deployed.
For development to work correctly this is the workaround I did.
The generated API uses a template like this for all queries in GTLQueryMyAPI.m
+ (id)queryForSearchWithObject:(GTLMyAPIMessagesSearchRequest *)object {
if (object == nil) {
GTL_DEBUG_ASSERT(object != nil, #"%# got a nil object", NSStringFromSelector(_cmd));
return nil;
}
NSString *methodName = #"myapi.search";
GTLQueryMyAPI *query = [self queryWithMethodName:methodName];
query.bodyObject = object;
query.expectedObjectClass = [GTLMyAPIMessagesContactListResponse class];
return query;
}
For this to work on development server one could substitute all these lines
query.bodyObject = object;
With
query.JSON = object.JSON;
This stops from wrapping the JSON in a "resource" field. Somehow I believe this shouldn't be done on deployment release version.
I'm still experimenting but believe this is the proper way (swift) to set up for testing on localhost....
let _service = GTLServiceBackendAPI();
_service.allowInsecureQueries = true;
_service.isRESTDataWrapperRequired = false;
_service.retryEnabled = true;
_service.fetcherService.allowLocalhostRequest = true;
_service.rpcURL = NSURL(string: "http://localhost:8080/_ah/api/rpc?prettyPrint=true")

OData4ObjC without using proxyclasses

I am using OData4ObjC, want to know is there a way to add/update/delete an entry in a table without using proxy classes. Just similar way the OData4j for Android does
e.g.,
OEntity havinaCola = c.getEntity("Products", 3).execute();
I am currently using proxy classes for the same as mentioned below,
proxy = [[serviceEntities alloc] initWithUri:#"sampleservices/producer.svc/" credential:nil];
QueryOperationResponse *response = [proxy execute:#"customers"];
NSMutableArray *array = [response getResult];
Thanks.
I have found one way to do the same i.e., as mentioned in the book written by Author 'Matthew Baxter-Reynolds' 'Multimobile Development (Building applications for the iPhone and Android Platform)' suggests method how to GET/UPDATE/DELETE/ADD entries.
Hope this is useful.
Thanks

AWS SDK for iOS Regions and Endpoints

I am testing Amazon's SimpleDB and downloaded the SDK for IOS
Got a bit frustrated that it doesn't say where to change the endpoint.
The default endpoint is sdb.amazonaws.com
but I would like to change to sdb.ap-southeast-1.amazonaws.com
Does anyone know where I can change this?
Found the solution on this page:
http://aws.amazon.com/articles/CloudFront/3912
In AmazonClientManager.m
sdb = [[AmazonSimpleDBClient alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY]; // existing code
sdb.endpoint = #"http://sdb.ap-southeast-1.amazonaws.com"; // add new line to set the endpoint
It's better to use one of the predefined constants rather than specifying the endpoint via string:
sdb = [[AmazonSimpleDBClient alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY];
sdb.endpoint = [AmazonEndpoints sdbEndpoint:AP_SOUTHEAST_1];

Resources