Skip to content

Instantly share code, notes, and snippets.

@guiled
Created March 26, 2015 15:26
Show Gist options
  • Save guiled/dd4b11f4cf292f3259e6 to your computer and use it in GitHub Desktop.
Save guiled/dd4b11f4cf292f3259e6 to your computer and use it in GitHub Desktop.
Appcelerator iOS calendar access crash with promises
// The following code doesn't work and makes your app crashes
// Because you MUST NOT use deferred code that access to calendar
Ti.Calendar.requestEventsAuthorization(function(e) {
Ti.API.info('Authorizations success : ' + e.success);
if (e.success) {
new Promise(function (resolve) {
Ti.API.info('A');
var cal = Ti.Calendar.getDefaultCalendar();
Ti.API.info('A cal id' + cal.id);
resolve(cal);
}).then(function (_cal) {
Ti.API.info('B cal id' + _cal.id);
return Ti.Calendar.getDefaultCalendar();
}).then(function (_cal) {
if (_cal) {
Ti.API.info('cal id' + _cal.id);
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment