Log in or register to post comments

TrackableEventHandler equivalent for iOS

April 4, 2013 - 10:06am #1

I need a simple way to detect when a target has been found or lost, analogous to the onTrackingFound() and onTrackingLost() callbacks in the Unity api (in fact those would be perfect). Unfortunately that trackable event handler only seems to exist for Unity? Is there an equivalent set of callbacks in the iOS api that will allow me to easily and simply alert other class objects to the detection of a target in the target database?

Thanks!

TrackableEventHandler equivalent for iOS

June 20, 2014 - 2:34pm #6

Hi i've been using a similar aproach to what you describe, and it works perfect when calling the notification. but when i try to do something with object attached to the notification (a NSString with a url) my app crashes with error exc_bad_access code=1 on the first line my object is use.

Im trying to get a url from the target metadata and then use this url to launch a web page. my code works perfectly when i use a constant string like this

- (void) urlButtonTapped:(id)sender
{
   url = [NSURL URLWithString:@"http://www.demotec.mx"];   
   if (![[UIApplication sharedApplication] openURL:url])
       
       NSLog(@"%@%@",@"Failed to open url:",[url description]);
}

but when i use a global string with the url on it instead of @"http://www.demotec.mx" my app crashes

 

hope someone can help me with this issue

TrackableEventHandler equivalent for iOS

April 8, 2013 - 9:22am #5

Thanks Nalin, that will work great. Appreciate your help.

TrackableEventHandler equivalent for iOS

April 8, 2013 - 3:04am #4

Hi,

The simplest way to achieve this would be to keep track of the number of trackable results in renderFrameQCAR(), which you can see here:

 

    QCAR::State state = QCAR::Renderer::getInstance().begin();

    NSLog(@"active trackables: %d", state.getNumTrackableResults());

 
What you could do is store this each frame, and as soon as it changes then you can trigger a callback, and the simplest way of doing this would be to use notifications.
 
So in renderFrameQCAR() when the number changes you could post it using something like this:
 

    NSNumber* numberofTrackables = [NSNumber numberWithInt:state.getNumTrackableResults()];

    

    [[NSNotificationCenter defaultCenter] postNotificationName:kUpdatedNumberofTrackables

          object:numberofTrackables

          userInfo:nil];

 
...and on the receiving end where you need the callback:
 

        [[NSNotificationCenter defaultCenter]

         addObserverForName:kUpdatedNumberofTrackables

         object:nil

         queue:[NSOperationQueue mainQueue]

         usingBlock:^(NSNotification *notification) {

             

             NSNumberobject:numberofTrackables = notification.object;

             NSLog(@"number of trackables found = %@"numberofTrackables);

             

 

 

             // do other work

 

         }];

 

 

The only other thing you may need to do is define the notification once 

 

NSString * const  kUpdatedNumberofTrackables = @"kUpdatedNumberofTrackables";

...and also again to refer to it externally:

extern NSString * const  kUpdatedNumberofTrackables;

 

HTH

N

 

TrackableEventHandler equivalent for iOS

April 5, 2013 - 10:23am #3

Hi Nalin, thanks for your reply.

Can you please recommend an approach to reliably achieve this in iOS? I've been looking at putting some checks in -(void)renderFrameQCAR, but I don't know if this would be the best approach.

TrackableEventHandler equivalent for iOS

April 5, 2013 - 10:14am #2

Sorry, this does not exist at the moment, but please log this as a feature request if you want the dev team to consider it in future.

thanks

N

Log in or register to post comments