Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Is it possible to add entry to local calendar of the device?
Started by alzaabi98 May 13 2014 03:38 AM

- - - - -
19 replies to this topic
calendar
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

alzaabi98

[GLOBAL: userInfoPane.html]
alzaabi98
  • Contributor

  • 354 posts
  • Corona SDK

Hi all,

 

is possible to add event entry to the local calendar of the device ?

 

my idea is when the user clicks on a button, the entry of the event with dates will be added to his calendar.

 

I didn't see any api to do that ?

 

Regards

Abdul



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,081 posts
  • Enterprise

To access the device's calender would require a plugin, which we currently do not have.  Corona Enterprise subscribers could do this.

 

Rob



[TOPIC: post.html]
#3

alzaabi98

[GLOBAL: userInfoPane.html]
alzaabi98
  • Contributor

  • 354 posts
  • Corona SDK

really there is no way ?? .. except enterprise..  it is very expensive for me ..

 

:(

 

Regards

Abdulaziz



[TOPIC: post.html]
#4

alzaabi98

[GLOBAL: userInfoPane.html]
alzaabi98
  • Contributor

  • 354 posts
  • Corona SDK

anyone has some tricks or external code that can work..

 

what about other calls such as ..

native.showAlert()

 

is it accessing the native APIs as well... if so then why the reset do not work ?

 

regards

Abdul



[TOPIC: post.html]
#5

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,081 posts
  • Enterprise

There seems to be a way to launch the calendar app from Corona.  You can do a:

 

system.openURL("calshow://")

 

That won't do anything more than launch the calendar.  I saw a wiki page that indicated that there were some parameters that could be passed, but it didn't explain what they meant.  So not much help there.

 

The other thing, if you want to add an entry to a calendar, you can create a .ical file on a web server somewhere and use system.openURL() to hit the URL for the .cal file and that should launch the calendar app adding the event to the calendar.  See:
 

http://stackoverflow.com/questions/1341627/is-there-an-iphone-url-shortcut-for-calendar

 

The last answer is the one I'm referring to.

 

Corona SDK uses Lua which in effect sits in it's own virtual machine.  You can make Lua calls and any API call we provide.  When you need something in native land that Apple and Google restrict like the Calendar, either we have to build an API call that bridges the Lua world to the Native world or you have to use Corona Enterprise so you can build that bridge.

 

We have an API call called "native.showPopup" that we use to access OS restricted app interfaces like the Calendar, but the Calender is one app we have not yet built support for.  You can use it to send an email, a text message, access Facebook and Twitter, and several other things. 

 

If you would like for Corona Labs to build that plugin, you could go to http://feedback.coronalabs.com and find the request for the Calendar and vote it up as something important to you.  If it gets enough votes, we might consider adding a plugin for the calendar.

 

Rob



[TOPIC: post.html]
#6

alzaabi98

[GLOBAL: userInfoPane.html]
alzaabi98
  • Contributor

  • 354 posts
  • Corona SDK

Thanks Rob,, i voted for the calendar,,

 

Now i am working in the workaround,, i tried few things but not working yet..

 

Shall the .ical file be generated on the fly and called via the system.openURL() or it should be called via the php file and the php generate .ical file and store somewhere in the web server..

 

Regards

Abdulziz



[TOPIC: post.html]
#7

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,081 posts
  • Enterprise

I don't have any real advice other than to get an .ical file on a URL that system.openURL() can reach.  If you need to use PHP to generate it on the server, or if you want to generate it in your app and then upload it.  You might even be able to generate it locally and create a file:// type URL.

 

You will have to experiment and see.

 

Rob



[TOPIC: post.html]
#8

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,081 posts
  • Enterprise

I tried to use a local file to do this, and it didn't work.  But using system.openURL to open a remote .ics file worked great.

 

Rob



[TOPIC: post.html]
#9

alzaabi98

[GLOBAL: userInfoPane.html]
alzaabi98
  • Contributor

  • 354 posts
  • Corona SDK

Good news.. how did you make .ics file ? Did you save it to webserver or you made it via php?

Regards
Abdul

[TOPIC: post.html]
#10

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,081 posts
  • Enterprise

I just hand wrote one using a text editor and FTP'ed it to my webserver to test.

 

I did it as a test.  My suggestions above don't change on this.  I wanted to verify if a locally accessed file would work, which doesn't.

 

Rob



[TOPIC: post.html]
#11

alzaabi98

[GLOBAL: userInfoPane.html]
alzaabi98
  • Contributor

  • 354 posts
  • Corona SDK

I have tested few things,, and here is what worked for me.. event it is not like the one initially imagined..

I used system.openURL with string I make before it with sending parameters via the url.. the php file will read the parameters  from the url and then make .ics file.. I hope this is useful for anyone who is interested for calendar..  the .ics will be downloaded and the use has the option then to add the event or not.

 

 

 

I was hoping by one click the event will be added locally but that was not possible as Rob mentioned due to lack of calendar API.

 

 main.lua file

 
 
display.setDefault( "anchorX",  0)
display.setDefault( "anchorY", 0)

local widget = require( "widget" )
local settings = { start="20140628T080000Z", ends="20140628T090000Z", name="Safety Meeting",description="Safety Meeting in the field",location="USA"}
 
 local params = {}
 params.body = "start=" .. settings.start .. "&ends=" .. settings.ends .. "&name=" .. settings.name.. "&description=" .. settings.description.. "&location=" .. settings.location
print(params.body)
local newURL = "http://omanevents.net/OmanEventsApp/ICS2.php?" .. params.body
print (newURL)
system.openURL( newURL )
 

 

 php file (ICS2.php)

 

<?php
$start = $_GET["start"] ;
$ends = $_GET["ends"] ;
$name = $_GET["name"] ;
$description = $_GET["description"] ;
$location = $_GET["location"] ;

class ICS {
    var $data;
    var $name;
    function ICS($start,$end,$name,$description,$location) {
        $this->name = $name;
        $this->data = "BEGIN:VCALENDAR\nVERSION:2.0\nMETHOD:PUBLISH\nBEGIN:VEVENT\nDTSTART:".date("Ymd\THis\Z",strtotime($start))."\nDTEND:".date("Ymd\THis\Z",strtotime($end))."\nLOCATION:".$location."\nTRANSP: OPAQUE\nSEQUENCE:0\nUID:\nDTSTAMP:".date("Ymd\THis\Z")."\nSUMMARY:".$name."\nDESCRIPTION:".$description."\nPRIORITY:1\nCLASS:PUBLIC\nBEGIN:VALARM\nTRIGGER:-PT10080M\nACTION:DISPLAY\nDESCRIPTION:Reminder\nEND:VALARM\nEND:VEVENT\nEND:VCALENDAR\n";
    }
    function save() {
        file_put_contents($this->name.".ics",$this->data);
    }
    function show() {
        header("Content-type:text/calendar");
        header('Content-Disposition: attachment; filename="'.$this->name.'.ics"');
        Header('Content-Length: '.strlen($this->data));
        Header('Connection: close');
        echo $this->data;
    }
}
$event = new ICS($start,$ends,$name,$description,$location);
$event->show();
echo $start

?>

 

note: the source of php file is stackoverflow.com but I did small modification on it.

 

Regards

Abdul



[TOPIC: post.html]
#12

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,081 posts
  • Enterprise

Great.  We did a tutorial on this (really just the concept) today.  This would be a good addition to it.

 

Rob



[TOPIC: post.html]
#13

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Corona Geek

  • 2,795 posts
  • Corona SDK

Thanks for both the tutorial and this nice script contribution! Great work!!!



[TOPIC: post.html]
#14

alzaabi98

[GLOBAL: userInfoPane.html]
alzaabi98
  • Contributor

  • 354 posts
  • Corona SDK

you are welcome mr ksan . ;) ..  this is the idea behind such forums , to share knowledge and work. it will be great if everyone share his resolution when he post a topic in this forum.. to me i think this is the best forum i have ever experienced in terms of responses and participation. we need to push more maybe toward sharing solutions.   

 

Abdul



[TOPIC: post.html]
#15

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Corona Geek

  • 2,795 posts
  • Corona SDK

I fully agree. Thanks once again.



[TOPIC: post.html]
#16

Charles McKeever

[GLOBAL: userInfoPane.html]
Charles McKeever
  • Contributor

  • 116 posts
  • Alumni

I was running into issues with spaces in the Name and Descriptions fields, so I required the socket.url library and escaped those fields during the population of the params.body table.

 

local url = require("socket.url")
display.setDefault( "anchorX", 0)
display.setDefault( "anchorY", 0)
local widget = require( "widget" )
local settings = {
     start='20140528T010000Z',
     ends='20140528T020000Z',
     name='Test Event',
     description='This is a description.',
     location='USA'
}
local params = {}
params.body = 'start=' .. settings.start ..
     '&ends=' .. settings.ends ..
     '&name=' .. url.escape(settings.name) ..
     '&description=' .. url.escape(settings.description) ..
     '&location=' .. settings.location
print(params.body)
local newURL = "http://opensourcemarketer.com/ICS2.php?" .. params.body
system.openURL( newURL )



[TOPIC: post.html]
#17

alzaabi98

[GLOBAL: userInfoPane.html]
alzaabi98
  • Contributor

  • 354 posts
  • Corona SDK

nice catch  . thanks man 

 

Abdul



[TOPIC: post.html]
#18

FearTec

[GLOBAL: userInfoPane.html]
FearTec
  • Contributor

  • 218 posts
  • Corona SDK

Thx, I added a bit of parameter checking on the PHP side to not deliver an ICS if incomplete data was received and cache expiration.

 

Would benefit from an API key (to block others accessing, data length limits, stripping of PHP/Injection/Hacking chars.

<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");header("Cache-Control: no-cache");header("Pragma: no-cache");

$inputsOK = True;		// Only Generate ICS if inputs are  OK

if (!isset($_SERVER[‘start’])) {
	$start = $_GET["start"] ;
	if ($start == "") {
		$inputsOK = False;
	}
} else {
	$inputsOK = False;
}

if (!isset($_SERVER[‘ends’])) {
	$ends = $_GET["ends"] ;
	if ($ends == "") {
		$inputsOK = False;
	}
} else {
	$inputsOK = False;
}

if (!isset($_SERVER[‘name’])) {
	$name = $_GET["name"] ;	
	if ($name == "") {
		$inputsOK = False;
	}
} else {
	$inputsOK = False;
}

if (!isset($_SERVER[‘description’])) {
	$description = $_GET["description"] ;
	if ($description == "") {
		$inputsOK = False;
	}
} else {
	$inputsOK = False;
}

if (!isset($_SERVER[’location’])) {
	$location = $_GET["location"] ;
	if ($location == "") {
		$inputsOK = False;
	}
} else {
	$inputsOK = False;
}

if ($inputsOK == TRUE) {

	class ICS {
	    var $data;
	    var $name;
	    function ICS($start,$end,$name,$description,$location) {
	        $this->name = $name;
	        $this->data = "BEGIN:VCALENDAR\nVERSION:2.0\nMETHOD:PUBLISH\nBEGIN:VEVENT\nDTSTART:".date("Ymd\THis\Z",strtotime($start))."\nDTEND:".date("Ymd\THis\Z",strtotime($end))."\nLOCATION:".$location."\nTRANSP: OPAQUE\nSEQUENCE:0\nUID:\nDTSTAMP:".date("Ymd\THis\Z")."\nSUMMARY:".$name."\nDESCRIPTION:".$description."\nPRIORITY:1\nCLASS:PUBLIC\nBEGIN:VALARM\nTRIGGER:-PT10080M\nACTION:DISPLAY\nDESCRIPTION:Reminder\nEND:VALARM\nEND:VEVENT\nEND:VCALENDAR\n";
	    }
	    function save() {
	        file_put_contents($this->name.".ics",$this->data);
	    }
	    function show() {
	        header("Content-type:text/calendar");
	        header('Content-Disposition: attachment; filename="'.$this->name.'.ics"');
	        Header('Content-Length: '.strlen($this->data));
	        Header('Connection: close');
	        echo $this->data;
	    }
	}
	$event = new ICS($start,$ends,$name,$description,$location);
	$event->show();
	echo $start;

} else {

	//header("Content-Type:text/plain");
	//Header('Connection: close');

}
?>


[TOPIC: post.html]
#19

alzaabi98

[GLOBAL: userInfoPane.html]
alzaabi98
  • Contributor

  • 354 posts
  • Corona SDK

FearTec  :) ,, cool addition,,.

 

Thanks

Abdul



[TOPIC: post.html]
#20

Dr Brian Burton

[GLOBAL: userInfoPane.html]
Dr Brian Burton
  • Enthusiast

  • 74 posts
  • Corona SDK

Fantastic work gentlemen!
Just a note for those who come later on the ICS format:
The \Z forces the time to GMT (Greenwich Mean Time), which could change the time you are trying to record in the calendar if you don't make the adjustment in your app (at least it did in my app).  
To set all times to the local timezone, remove the Z from your lua time that is sent to the server and the \Z from the php file.




[topic_controls]
[/topic_controls]