GAIDictionaryBuilder fails for NSNumber values - ios

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.

Related

NativeScript: Get string from interop.reference

To start, here is my code:
var buffer = malloc(interop.sizeof(interop.types.UTF8CString));
var fillBuffer = mac.getBytes(buffer);
var bytes = new interop.Reference(interop.types.UTF8CString, buffer);
var hexMac = bytes[0];
The variable 'Mac' is an NSData objected retrieved from CoreBluetooth. It is the scan response from a BLE device, which contains the peripheral's MAC address (00:0b:57:a2:fb:a0).
This problem is linked to THIS question I had posted earlier.
The solution provided is great; however, I cannot seem to implement this in nativescript :
(instancetype)stringWithFormat:(NSString *)format, ...;
Intellisense tells me the method doesnt exist on type NSString.
Due to that issue, I decided to go another route (as you can tell). I am filling a buffer with the bytes of the MAC address. In the code above, bytes[0] equates to 0xb57a2fba0.
I am now trying to convert that (which is an interop.Reference) into a string that I can store on the back-end (preferably in the xx:xx:xx:xx:xx format).
I have been at this all weekend, and cannot seem to find a solution. I even broke down objc!foundation.d.ts to figure out if stringWithFormat was supported, to no avail.
The nativescript community slack was unable to provide a resolution as well.
Please help if you can!
I don't know anything about NativeScript at all, but given the other code you wrote, I assume you're calling +alloc first, and so mean to use -initWithFormat: (an instance method that initializes) rather than +stringWithFormat: (a class method which handles allocation and initialization).

Parse: withoutDataWithClassName is now outDataWithClassName?

I've migrated my iOS parse SDK from the old Parse SDK to the version released to support a Parse stack hosted on my own infrastructure.
I have my project set up with SocketIO and decided it would be more efficient to append new Parse Objects sent from the server to my iOS apps model instead of making a new network request whenever the model changed, therefore I needed to instanciate a Parse object with an existing object ID.
To do that I used the following code snippet:
let appendError = PFObject(withoutDataWithClassName: "MachineError", objectId: id)
appendError.setValue(errorCode, forKey: "errorCode")
appendError.setValue(errorMessage, forKey: "errorMessage")
appendError.setValue(newDate, forKey: "createDate")
appendError.setValue(serial, forKey: "serialNumber")
appendError.setValue(status, forKey: "status")
appendError.setValue(false, forKey: "completed")
This code used to work fine when I was running xcode v7.1 but since this-morning when I upgraded to xcode 7.3, I was presented with an error that withoutDataWithClassName was not a valid parameter, it offered me outDataWithClassName as an alternative but the naming of that parameter did not sound as declarative as the previous. I did some reading through the PFObject documentation for iOS, but I could not find any details depicting what outDataWithClassName actually does.
I can only assume that it may be a typo on behalf of the Parse team, but I may be wrong. Could anyone here confirm whether withoutDataWithClassName is equivalent to outDataWithClassName?
Looks like it was a mistake related to automatic Objective-C to Swift conversion. It was reported as in issue in the repo, and a fix was committed 3 days ago.
In short, outDataWithClassName will do the same thing as withoutDataWithClassName for now, but since the current method name is rather uninformative, I would recommend updating Parse soon to get the fix.

How to convert EDAMTimestamp to NSDate with Evernote Cloud SDK for iOS

I tried Evernote Cloud SDK 2.0.6 for iOS. When I fetch the EDAMSyncChunk and the note data from Evernote service, created (and also updated and deleted) property as NSNumber type in EDAMNote instance has following values for example:
1350039844000
765020000
The former seems to be the UNIX time with milliseconds, so I can convert the value to NSDate object, getting "2012-10-12 20:04:04" (JST).
The latter, however, does not seem to be the correct UNIX time because the value cannot be converted to the acceptable time regardless of removing the last three digits:
765020000 ---> "1994-03-30 18:33:20" (JST)
765020 ---> "1970-01-10 05:30:20" (JST)
How can I get the correct time from the latter case? (I doubt that "765020000" results from something like "xxxx765020000" in 32bit environment, though I cannot check the environment now... sorry)
Please help.
Thanks.
on my project, I got it working like this (in swift):
let date = NSDate(EDAMTimestamp: note.created.longLongValue)

Firebase iOS FQuery by child value is failing intermittently

I am using Firebase iOS framework. Don't see an obvious way to tell the build version I am using. I am testing on an iOS simulator usually.
I implemented a helper function to find certain data by indexed key. I have created indexes on these keys in the security rules, but that should not be necessary. My data and query are very similar to the dinosaur query by height example in the firebase docs. My data is flattened to //{key: value, key: value, ...}. E.g., Player/-JwISoamh_jRhYeKvKLk will contain a dictionary like:
{
"height": "1.89",
"firstName": "LeBron",
"lastName": "James"
}
I use my code to find all players with lastName === "James". So, in the code below the ObjBase would point to /Player and childKey = "lastName" and value="James". I expect querySnaphot to contain 1 child with the node for "JwISoamh_jRhYeKvKLk".
Even though the data is in my test data in my app on firebaseio.com and the values match up, this code returns me a querySnapshot.childrenCount == 0:
FQuery *query = [[objBase queryOrderedByChild:childKey] queryEqualToValue:value];
[query observeSingleEventOfType:FEventTypeValue withBlock:^(FDataSnapshot *querySnapshot) {
Until I change the FEventTypeValue to FEventTypeChildAdded. At that point I get data, but it is not an array of nodes in the querySnapshot.children, but values. As soon as I change the code back to FEventTypeValue my query, exactly as it was before, will work for some period of time (multiple runs of the app). Possibly it stops working when I nuke the data for a bunch of new changes. Maybe it is being cached locally after that initial load.
Perfectly willing to believe I am doing something wrong, but I cannot see what and the fact that it works after I "seed it" with the ChildAdded leads me to think it is an async issue or some initial setup I need to do.
Thanks!!

My NSDictionary somehow has multiple values for one key

I have been attempting to debug a issue with my code, and just came upon an odd phenomenon. Found this in the debug area when a breakpoint was triggered:
Am I correct in observing that there are multiple values for this key: #"6898173"??
What are possible causes of this? I do not set those key-value pairs using the string literal, but by getting a substring of a string retrieved and decoded from a GKSession transmission.
I still have this up in the debug area in xcode, incase theres anything else there that might help.
EDIT:
By request, here is the code that would have created one of the two strings (another was created at an earlier time):
[carForPeerID setObject:[[MultiScreenRacerCarView alloc] initWithImage:[UIImage imageNamed:#"simple-travel-car-top_view"] trackNumber:[[[NSString stringWithUTF8String:data.bytes] substringWithRange:range] intValue]] forKey:[[NSString stringWithUTF8String:[data bytes]] substringFromIndex:9]];
The string in data might look something like this:
car00.0146898173
EDIT:
Code that sends the data:
[self.currentSession sendData:[[NSString stringWithFormat:#"car%i%#%#", [(MultiScreenRacerCarView *)[carForPeerID objectForKey:peerID] trackNumber], speed, [(MultiScreenRacerCarView *)[carForPeerID objectForKey:peerID] owner]] dataUsingEncoding:NSUTF8StringEncoding] toPeers:#[(NSString *)[peersInOrder objectAtIndex:(self.myOrderNumber + 1)]] withDataMode:GKSendDataReliable error:nil];
Sorry its hard to read. Its only one line.
What you're seeing is a debugger "feechure". When you have a mutable dictionary and modify it, the debugger may not show you the correct view of the object.
To reliably display the contents of an NSMutableArray or NSMutableDictionary, switch to the console and type po carForPeerID.

Resources