How do you cancel a Nest ETA using Firebase on iOS? - ios

According to the nest API docs:
"To cancel an eta, send estimated_arrival_window_begin = 0. Check that you're sending an integer (0) in this call, not a string ("0"), or the call will fail."
See https://developers.nest.com/documentation/cloud/eta-reference/
My code is based on the iOS NestDK sample which uses Firebase.
I set things up using the addSubscriptionToURL method as follows: ​
[[FirebaseManager sharedManager] addSubscriptionToURL:[NSString stringWithFormat:#"structures/%#/eta", structureId] withBlock:^(FDataSnapshot *snapshot) {}];
I can then make successful calls to set an eta window for a specific trip.
However, i can't seem to be able to cancel the eta for the same trip. If i just specify the trip_id and estimated_arrival_window_begin properties i get an error message complaining that the estimated_arrival_window_end field is missing.
NSMutableDictionary *values = [[NSMutableDictionary alloc] init];
[values setValue:[_tripId UUIDString] forKey:#"trip_id"];
[values setValue:[NSNumber numberWithInt:0] forKey:#"estimated_arrival_window_begin"];
[[FirebaseManager sharedManager] setValues:values forURL:[NSString stringWithFormat:#"structures/%#/eta", structureId]];
I tried also setting estimated_arrival_window_end to 0 but i then get an error message saying that the estimated_arrival_window_begin is in the past. It seems to be interpreting the 0 value as the beginning of time. Well some time in 1970 anyway!
What am i doing wrong here?!
Thanks!

Are you using a Nest account with virtual devices created with the Nest Home Simulator? There appears to be a bug using virtual devices versus real devices. Please try using a Nest account with real devices.

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.

Twilio iOS client not passing parmeters on connect

Yet another problem with Twilio for me. So, I'm trying to connect with another user with parametes. Here's my code:
-(void)connect:(CDVInvokedUrlCommand*)command {
NSLog(#"The content of dict is%#",[command.arguments objectAtIndex:0]);
NSDictionary *dict = [command.arguments objectAtIndex:0];
for(NSString *key in [dict allKeys]) {
NSLog(#"%#",key);
NSLog(#"%#",[dict objectForKey:key]);
}
[self.device connect:dict delegate:self];
}
Problem: no matter what I have in NSDictionary nothing gets passed to server. I have tryied with number of parameters, nothing gets passed. Not even To parameters, on non of other, custom ones. It works for every other platform, but not for iOS.
What em I missing here? According to docs it should work, connect method is taking NSDictionary as input,
-connect:(NSDictionary*)params delegate:(id<TCConnectionDelegate>)delegate, so where should I look?
PS. This is yet another big problem Twilio lib that I had in last few days. Im getting enough of it.
OK, the problem was that I was passing NSDictionary with key that had integer value. The -connect method accepts only <NSString NSString> NSDictionary.
Let's figure this out. It’s not entirely clear from your code sample what exactly you've passed in as arguments so forgive me if I suggest something you might've already tried.
What happens if you try something like this?
NSDictionary *params = #{#"To": "number_to_dial"};
_connection = [_phone connect:params delegate:self];
If this does not work, we can be certain the problem lies in the account, token, or app itself.
The iOS sample shows how to pass the dialing parameters, however it’s still the developer’s responsibility to create proper ​TwiML that contains the dialing command tags that Twilio recognizes.
If the call is hitting your server though without any parameters being passed in, there should be a Twilio CallSid available in the TCConnectionDelegate.connectionDidConnect: method. If that's the case, I would suggest contacting support with that Sid and we can dig more info from the server to see what parameters are being passed.
Here's how to retrieve the CallSid:
- (void)connectionDidConnect:(TCConnection *)connection {
NSString *callsid = [[connection parameters] objectForKey:#"CallSid"];
...
}
Could you see if you are able to see this callback method being called and try to provide the CallSid if possible?

Nest Thermostat Away Status changes back to home

Nest thermostat SDK, using iOS sample code from Nest as reference.
Setting the temperature is outlined in the sample code. Setting the away status to away or home (string value saed to firebase is not).
From a previous question Change Away Status on Nest Thermostat (Nest API) im changing the away status:
self.rootFirebase = [[Firebase alloc] initWithUrl:#"https://developer-api.nest.com/"];
Firebase *structuresRef = [self.rootFirebase childByAppendingPath:#"structures"];
Firebase *thisStructureRef = [structuresRef childByAppendingPath: #"structure_id_0"];
Firebase *awayRef = [thisStructureRef childByAppendingPath: #"away"];
// Set Status
[awayRef setValue:#"away"];
This reflects as away in the logs. Getting this to stick is causing a problem.
After being set away the logs a second later show it's back to home again.
The stat seems to be overriding the request from the app, whatever's on the stat has priority
- (void)addSubscriptionToURL:(NSString *)URL withBlock:(SubscriptionBlock)block {
Firebase *newFirebase2 = [self.rootFirebase childByAppendingPath:#"structures"];
[newFirebase2 observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
// Put structures int a dictionary
NSMutableDictionary *dict = snapshot.value;
NSLog(#"\n\n******** STATUS: Away Status = %# **********\n\n", [dict valueForKey:#"away"]);
}];
}
Has anyone successfully set the away status with the nest SDK? Ive tried setting the away status immediately when the app launches in many different sections of the apps model just to try and get the status to stay. Not anything on a google search to assist either, apart from a sample project on github that was not suitible
are you sure you are calling the structures correctly? it supposes to be following:
structures/VqFabWH21nwVyd4RWgJgNb292wa7hG_dUwo2i2SG7j3/away
depends on your actual structure_id, refer here

Objective-C HealthKit identify if source is from Apple iPhone or Apple Watch

I have an app where I am trying to integrate the HealthKit and pull steps related data aggregated by day using the HKStatisticsCollectionQuery. Requirement is to pull steps data specific to only iPhone and Apple Watch devices separately (no de-duplication) which have contributed to the health app.
The HKSource class only exposes the following properties:
name - Cannot be used as the user can change this to anything from just 'XXXX iPhone'
bundleIdentifier - Provides us the UUID for the device (unique per device, so different for every iPhone/Watch), and it looks like com.apple.health.UUID, here's what the Apple documentation says : "For apps, this property holds the app’s bundle identifier. For supported Bluetooth LE devices, this property holds a UUID for the device."
I am able to pull all sources (using a HKSourceQuery) which have the bundleIdentifier prefix of 'com.apple.health', but am unable to deduce which is an Apple iPhone versus which is an Apple iWatch.
Has anybody faced a similar situation before, and is there any other way to identify which source is an iPhone or Apple Watch?
Any help would be great!.Thanks!
Not the best solution but, I have figured out a way to distinguish between the watch and the phone using the following process:
I noticed that all step data coming from the iPhone/Watch have the following bundleIdentifier format:
com.apple.health.DeviceUUID
Note that manually entered data into the Health app has a bundle identifier of com.apple.Health (with a capital 'H').
So, first thing, get the device name for the phone using:
NSString *deviceName = [[UIDevice currentDevice] name];
Next, fetch all the sources for which there is a prefix match of 'com.apple.health' in the bundleIdentifier. This should give you the iPhone and the Apple watch as the valid sources and ignore the manual entries and all other apps.
Next, check if the name of the device is the same in the source, then its your iPhone, the other source should be your Apple Watch.
Here's a sample source query for fetching the sources :
- (void)fetchSources
{
NSString *deviceName = [[UIDevice currentDevice] name];
NSMutableArray *dataSources = [[NSMutableArray alloc] init];
HKQuantityType *stepsCount = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
HKSourceQuery *sourceQuery = [[HKSourceQuery alloc] initWithSampleType:stepsCount
samplePredicate:nil
completionHandler:^(HKSourceQuery *query, NSSet *sources, NSError *error)
{
for (HKSource *source in sources)
{
if ([source.bundleIdentifier hasPrefix:sourceIdentifier])
{
if ([source.name isEqualToString:deviceName])
// Iphone
else
// Apple Watch
[dataSources addObject:source];
}
}
}];
[self.healthStore executeQuery:sourceQuery];
}
You can now create a predicate with each source for your data pull using the NSPredicate class:
NSPredicate *sourcesPredicate = [HKQuery predicateForObjectsFromSource:source];
Note that my first thought was to match the UUID, but when I generate a UUID using the NSUUID class, it does not match with the one present in the bundle identifier in the pulled sources.
Also, you can change the name of the phone to whatever you want, it will automatically update in the Health app as well.
As I said, not the best solution but works for me, and it's the only way I could find to do this. Please let me know if you were able to find a better solution. Thanks.

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.

Resources