I'm trying to pass a variable to my backgroundService.js and them set the push time through this variable... but it is not working... only work if I manually set the time in milliseconds ...
// app.js
var timer = 2000
Ti.App.Properties.setString( 'pushTime', timer )
var service = Ti.App.iOS.registerBackgroundService({
url:'bg.js'
})
// bg.js
var timer = Ti.App.Properties.getString( 'pushTime' )
Ti.API.info( timer )
var notification = Ti.App.iOS.scheduleLocalNotification({
alertBody:"Passou a bebedeira ja?",
alertAction:"Ok",
userInfo:{"hello":"world"},
sound:"pop.caf",
badge: 1,
date:new Date(new Date().getTime() + timer )
})
someone knows why when I use timer
instead 2000
it not work?
Thanks
3.1.1
iOS
DHennrich, Ti.API.info( timer )
returns 2000 doesn't mean that 2000 is a type of number. Actually it is a string since you're using setString method to store the value and retrieve it using getString()
. When you use setString
it stores the value as a string and getString
always returns a string avlue. That's why your code worked when you used 2000 instead of timer
variable.
From API Documentation
getString( String property, [String default] ) : String
Returns the value of a property as a string data type. Parameters
property : String Name of property. default : String (optional) Default value to return if property does not exist.
Returns
String
You can use setInt or setDouble instead of setString
to set a property and to retrieve use getInt or getDouble respectively.
Try to store the value using Ti.App.Properties.setInt( 'pushTime', timer );
and you can retrieve the value using
var timer = Ti.App.Properties.getInt( 'pushTime' );
I hope it resolved your issue.