How to trigger code

54 views
Skip to first unread message

arvidsso...@gmail.com

unread,
Sep 14, 2015, 10:48:27 AM9/14/15
to plot-users

Hi!


I am a little bit confused about how the geotrigger-handler interact with the rest of my Titanium IOS-app when writing something in the resources/plotgeotriggerhandler.js. I have read the documentation but still not get it. The documentation says that you cannot reference global variables or views from the plotgeotriggerhandler.js. But when reading about the geotriggers it says that you can "use them as trigger events for your own code”.


I am trying to change a variable in my app.js (classic, non-alloy) when entering a geofence called "zoneA". Lets say I want an entrance to change:


var enteringzoneA = 0


to be 


enteringzoneA = 1


If the app is in the background this eventtrigger can wait until the app is open again. If the app is already open this should happen directly. 

Is this possible? Or can you only trigger Plot related code?

Thanks for taking a look at my question!


Andreas

Mark van der Tol

unread,
Sep 16, 2015, 7:53:17 AM9/16/15
to plot-users
Hi Andreas,

It is indeed correct you cannot use global variables from the geotrigger handler. The reason for that is that script is run in the background, so it is possible that the rest of the scripts aren't even loaded yet/anymore. Even with this limitation you can still do some interesting stuff, for example remembering whether somebody entered a certain area. 

You could remember the trigger in the app settings. You run a snippet like this in the handler:

Ti.App.Properties.setBool('key', true);

and then a snippet like this in your app code:

var value = Ti.App.Properties.getBool('key');

Does this answer your question? Please let me know if something is still unclear.

Kind regards,
Mark van der Tol
Plot Projects

Andreas Arvidsson

unread,
Sep 28, 2015, 12:52:03 PM9/28/15
to plot-users
Hi Mark!

Thanks for your answer, it should give the tool I need. Great. But I been trying your suggestion and don't get it to work. What is the problem with the code below? 

I want my app (when it is opened or resumed) to tell if I have visit a zone. With my current code I get notifications when I enter a zone but when I open the app som few second later the alert always say I have not made a visit. 

A second question: Even if it would work, how do I make it remember which zone I have entered?

Once a again, thanks for your reply.

Andreas

////////////////In plotgeotriggerhandler.js//////////////////////////////

plot.addEventListener("plotNotificationReceived", function(){

Ti.App.Properties.setBool(”key", true);

});


plot.initPlot(config);



//////////////////In app.js//////////////////////////////////////////////////


var plot = require('com.plotprojects.ti');


plot.initPlot({ geotriggerHandlerEnabled: true });


var value = Ti.App.Properties.getBool("key");


Ti.App.addEventListener('app:resumed', function(e){

value = Ti.App.Properties.getBool("key");

askifvisited ();


});



askifvisited ();



function askifvisited (){


if (value === true){


alert("you have visit zone A");


}


else


{


alert("you have NOT visit zone A");


}


}


//////////////////////////////////////////////////////////////////////////

Mark van der Tol

unread,
Sep 30, 2015, 3:51:36 AM9/30/15
to plot-users
Hi Andreas,

The code in plotgeotriggerhandler.js isn't correct. You don't have to register event handlers there. At our Github page is an example that shows how a geotrigger handler should look like.

Kind regards,
Mark van der Tol
Plot Projects

Andreas Arvidsson

unread,
Oct 2, 2015, 6:05:50 AM10/2/15
to plot-users
Ah! Thanks! Just to be sure even if it sounds a bit stupid: I need to do what is called "create geotrigger campaign" not only  a  "notification" in the dashboard to use the geotriggerhandler? Might be the reason why I get notifications but don´t get your example above to work:)

The thing is, when I try to create a geotrigger campaign in dashboard I get:

"Something went wrong with this dashboard request.

  • Could not complete this action because of the following reason: The request content was malformed: requirement failed: Either search term or country has to be defined when creating a campaign (not both)"
What  does "search term" mean in this case? I tried all types of alternatives the dashboard gives me, both with or without setting country and still gets this message. What is I don´t understand?

Once again, thanks for your help!

Andreas

Mark van der Tol

unread,
Oct 2, 2015, 10:07:08 AM10/2/15
to plot-users
Hi Andreas,

There is an issue with creating a geotrigger campaigns with a new geofence. If you select "Select set of Geofences" then it should work. At that screen you can enter a search term to search for geofences.

We will be fixing the issue within the next couple of days.

Kind regards,
Mark van der Tol

Andreas Arvidsson

unread,
Oct 2, 2015, 10:38:52 AM10/2/15
to plot-...@googlegroups.com
Thanks for your fast response. Now it works!

Andreas

--
You received this message because you are subscribed to a topic in the Google Groups "plot-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/plot-users/VYYf3BfHhl4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to plot-users+...@googlegroups.com.
Visit this group at http://groups.google.com/group/plot-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/plot-users/9fef9e12-69c9-46ba-8fb0-0133c13cd40f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Andreas Arvidsson

unread,
Oct 15, 2015, 6:09:52 AM10/15/15
to plot-...@googlegroups.com
Hi again Mark,

Back to your first example in this thread. You say that you use the app.properties to remember if the user have entered a certain area. But the 'key', true will only say if the user has entered any, not a certain, area. Or am I wrong? I been trying to use: 

Ti.App.Properties.setString('key', geotrigger);

But it only givs me "{,,," when i open the app and gets the string. How do you do to remember which certain area that has been entered using geotriggers?

All best,

Andreas
--

Jan-Pieter van den Heuvel

unread,
Oct 16, 2015, 7:55:33 AM10/16/15
to plot-...@googlegroups.com
Hi Andreas,

You can use JSON.stringify() to turn the geotrigger into a string or use the geotrigger.identifier or geotrigger.data (which you can set in the dashboard) fields to store information about the geotrigger. Have a look at the example code for the GeotriggerHandler in the documentation.

Kind regards,
Jan-Pieter

--
You received this message because you are subscribed to the Google Groups "plot-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plot-users+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Jan-Pieter van den Heuvel
Plot Projects I Development



Follow us on Twitter
Find and connect with us on Facebook
Keep up with us on our blog

Reply all
Reply to author
Forward
0 new messages