I want to just show events published by my Electron.
The Particle iPhone app shows the event coming from Electron ok.
Here’s my code within viewDidLoad()…
SparkEventHandler Electron_publication_handler = ^(SparkEvent *event, NSError *error)
{
printf("\n%s: E L E C T R O N P U B L I C A T I O N ", __FUNCTION__ );
if (!error)
{
dispatch_async(dispatch_get_main_queue(), ^{
printf("\n"); NSLog(@"got event with name %@ and data %@",event.event,event.data);
});
}
else
{
printf("\n"); NSLog(@"Error occured: %@",error.localizedDescription);
}
};
printf("\n%s: Start subscription.", __FUNCTION__ );
// subscribeToMyDevicesEventsWithPrefix
self.eventListenerID_A = [[SparkCloud sharedInstance] subscribeToAllEventsWithPrefix:nil handler: Electron_publication_handler ];
printf("\n%s: init Electron_publication_handler done.\n", __FUNCTION__ );
Also, don’t you want to use subscribeToMyDevicesEventsWithPrefix:? The one you’re using, subscribeToAllEventsWithPrefix:, will get all public events from everybody since you’re passing nil for the prefix.
Where in the process should this SparkEventHandler subscription handler be initialized?
I’ve tried it in viewDidLoad(), and I’ve tried it within the loginWithUser callback.
Should initialization of SparkEventHandler be immediately before setting id eventListenerID ?
That was the problem, Ric. Now, handler init’d in viewDidLoad is picking up publications from Electron, which is absolutely totally cool to finally see.
I need this in order to implement GPS data buffering down in the asset tracker Electron for when either mobile (iPhone) or Electron is offline… Lots o’ fun!