Is it possible to use the Google Translate api with iOS? - ios

How do I use the google translate API with iOS 6.0? I have tried googling the documentation and tried to research it, but I can't find anything that is updated since google made the api to be no longer free.
The only thing I have been able to find was this, but it didn't really help much because I need to use the api key that I have, but I have no idea how to.
http://www.raywenderlich.com/1448/how-to-translate-text-with-google-translate-and-json-on-the-iphone

This seems up to date: https://developers.google.com/translate/v2/getting_started
(completely meta: Oops! Your answer couldn't be submitted because:
body must be at least 30 characters; you entered 23)

Yes, it is. Once you get your Google key, just plug it into FGTranslator. Note, generate a "server" key, since the Google Translate API does not currently support iOS keys.
It's just a one-line call to the translate function after that.
FGTranslator *translator = [[FGTranslator alloc] initWithGoogleAPIKey:#"your_google_key"];
[translator translateText:#"Bonjour!"
completion:^(NSError *error, NSString *translated, NSString *sourceLanguage)
{
NSLog(#"translated from %#: %#", sourceLanguage, translated);
}];

Related

Create Pin PDKResponseObject response not consistent with documentation

We are creating a pin in a specific Board by using the method
createPinWithImageđź”—onBaord:description:progress:withSuccess:andFailure:
We read in the documentation (here: https://developers.pinterest.com/docs/api/overview/ and here: https://github.com/pinterest/ios-pdk/blob/master/Pod/Classes/PDKClient.h#L417) that this method should return a PDKResponseObject *responseObject with the ID, URL, clickthrough URL and description of the created Pin.
We have been creative enough to try to access the ID of the Pin and its URL using any possible key (#"id", #"identifier", #"url", #"NSUrl") but the values returned are always nil. In fact the PDKResponseObject returns only 2 keys: Board ID and Pin Description.
What should we do to access the ID or, at the very least, the URL of the newly created Pin?
Does anybody have the same issue?
Despite multiple attempts and after having tried to discuss this issue with the Pinterest development Team, this still remains.
Testing a solution becomes also extremely difficult considering the new limitation Pinterest has imposed on not approved apps (which include all apps under development by definition).
For now, I only found a way around by calling a new request to get all pins in a specific board and get the first in the resulting array (which is the last posted):
//Create pin in Pinterest
[[PDKClient sharedInstance]createPinWithImage:image link:urlToShare
onBoard:reference description:message progress:nil
withSuccess:^(PDKResponseObject *responseObjectCreation) {
//Previous block does not return pin id so a new call is required
[[PDKClient sharedInstance]getBoardPins:reference fields:[NSSet
setWithArray:#[#"link"]] withSuccess:^(PDKResponseObject
*responseObject) {
//Get id of last pin
NSArray *pinIDs = [[NSArray arrayWithArray:[responseObject
pins]]valueForKey:#"identifier"];
NSString *postId = [pinIDs objectAtIndex:0];
}];
}];
By the way, the right key for the pin ID is "identifier" and not "id" or "ID" as said in the API documentation. Just found out by trying multiple times and checking the Pinterest Example app in GitHub.
Hope this helps other people who are fighting the same problem.

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

Saving an iCloud Drive security scoped URL on iOS (UIDocumentPickerViewController)

I'm trying to save the security scoped URL returned from iCloud document picker (UIDocumentPickerViewController)
The documentation states:
If the URL is not a ubiquitous URL, save a bookmark to the file using
the
bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error:
method and passing in the NSURLBookmarkCreationWithSecurityScope
option. Calling this method creates a bookmark containing a
security-scoped URL that you can use to open the file without further
user intervention.
However, the compiler says that NSURLBookmarkCreationWithSecurityScope is not supported on iOS.
Anyone know what's going on here....?
After further digging, it turns out option NSURLBookmarkCreationWithSecurityScope is NOT needed at all when creating bookmark data in IOS. It's an option for OS X. You can just pass nil for the option field. I think Apple's document is confusing at the best.
However, you do need to call startAccessingSecurityScopedResource before creating the bookmark and make sure the call returns 1 (success) before proceed. Otherwise, bookmark creation will fail. Here is the sample code:
if ([url startAccessingSecurityScopedResource]==1) {
NSError *error;
NSData *bookmark = [url bookmarkDataWithOptions:nil
includingResourceValuesForKeys:nil
relativeToURL:nil
error:&error];
if (error) {
//handle error condition
} else {
// save your bookmark
}
}
[url stopAccessingSecurityScopedResource];
Again Apple's document is confusion at the best! It took me a lot of time to find out this. Hope this helps.
I ran into the same issue today, and indeed the compiler says NSURLBookmarkCreationWithSecurityScope is not available on iOS.
But to my surprise, if I use the raw constant instead (NSURLBookmarkCreationWithSecurityScope maps to ( 1 << 11 ), the method seems to work. It returns a valid bookmark data object, and when I call [[NSURL URLByResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:stale], a valid security-scoped NSURL is returned and I can access the files and directories. Also, I tested these with iCloud Drive. And the documentation only says this should work for third-party document providers.
I am not sure how reliable this approach is, because it seems that Apple engineers didn't have time to finish up this feature, so disabled it in the last minute. Or it could be simply a bug in the header file. If anyone finds out more about this, please comment.

GAIDictionaryBuilder fails for NSNumber values

I am trying to send commerce transaction data to google analytics on iOS with V3 SDK. I am building the data dictionary using GAIDictionaryBuilder class provided by Google (which is not open source unfortunately). For both createTransactionWithId and createItemWithTransactionId calls, my NSNumber values (revenue, price, etc.) are failing to be added to dictionary data properly. Here is the sample code:
NSMutableDictionary* test = [[GAIDictionaryBuilder createTransactionWithId:(NSString *)transactionId
affiliation:(NSString *)affiliation
revenue:(NSNumber *)revenue
tax:(NSNumber *)tax
shipping:(NSNumber *)shipping
currencyCode:(NSString *)currencyCode] build];
NSLog(#"revenue: %#", revenue);
NSLog(#"TR data: %#", test);
// if I explicitly set the value, IT WORKS!!!!
[test setObject:revenue forKey:#"&tr"];
NSLog(#"TR data FIXED??: %#", test);
In the output, I see revenue correctly, then when logging test dictionary I see the following line corresponding to revenue data:
"&tr" = "<null>";
Then, for the manual fix attempt, I see
"&tr" = "15.25";
as expected.
Here are some clues:
I use the same code in a different project compiled in a different OSX machine without any issues like this.
The transactions are in TRY (Turkish Lira), I suspect Google is trying to fix the separator (',' in Turkish vs '.' everywhere else), but as said above, the other app is also using TRY.
So the question is, why "<null>", why and how does it fail to convert a proper NSNumber to this bizarre value?
Eventually, I fixed the issue by working around it. I assigned the NSNumber to a new one (by getting its floatValue) and it seemed to fix the null values.
By the way, google analytics library version 3.07 readme mentions a similar issue as fixed however neither 3.03 nor 3.07 actually fixed my problem.

When using the Pocket API in an iOS app, is retrieval of articles only handled through JSON?

For those that have integrated Pocket into an app (further than just saving articles, I need to retrieve) when you go to retrieve a list of the users articles, is it only handled through JSON (as discussed here), or can you do it somehow with the Objective-C SDK directly?
If so, would I just be best off using a JSON framework to integrate it into my app?
I only ask because there appears to be a native way to save articles, and I was hoping there was a way to retrieve them as well, but I can't seem to find anything about it listed.
If you check out the source of the SDK on Github, you'll see there is a method to call any API. So it does appear that you can use the SDK to do more than just share.
Edit: You'd probably need to do something like this (untested code)
NSDictionary* argumentDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
#"010101", #"consumer_key",
#"101010", #"access_token",
#"simple", #"detailType", nil]; //etc
[[PocketAPI sharedAPI] callAPIMethod:#"get"
withHTTPMethod:#"POST"
arguments:argumentDictionary
handler:^(PocketAPI *api, NSString *apiMethod, NSDictionary *response, NSError *error){
// handle response here!
}];

Resources