Created
March 26, 2015 15:26
-
-
Save guiled/dd4b11f4cf292f3259e6 to your computer and use it in GitHub Desktop.
Appcelerator iOS calendar access crash with promises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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