{"action":"opened","issue":{"url":"https://api.github.com/repos/katzer/cordova-plugin-local-notifications/issues/520","labels_url":"https://api.github.com/repos/katzer/cordova-plugin-local-notifications/issues/520/labels{/name}","comments_url":"https://api.github.com/repos/katzer/cordova-plugin-local-notifications/issues/520/comments","events_url":"https://api.github.com/repos/katzer/cordova-plugin-local-notifications/issues/520/events","html_url":"https://github.com/katzer/cordova-plugin-local-notifications/issues/520","id":69329211,"number":520,"title":"[iOS] You have to wait for previous scheduling/cancel success callback until you can to make changes again","user":{"login":"jtomaszewski","id":1862580,"avatar_url":"https://avatars.githubusercontent.com/u/1862580?v=3","gravatar_id":"","url":"https://api.github.com/users/jtomaszewski","html_url":"https://github.com/jtomaszewski","followers_url":"https://api.github.com/users/jtomaszewski/followers","following_url":"https://api.github.com/users/jtomaszewski/following{/other_user}","gists_url":"https://api.github.com/users/jtomaszewski/gists{/gist_id}","starred_url":"https://api.github.com/users/jtomaszewski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jtomaszewski/subscriptions","organizations_url":"https://api.github.com/users/jtomaszewski/orgs","repos_url":"https://api.github.com/users/jtomaszewski/repos","events_url":"https://api.github.com/users/jtomaszewski/events{/privacy}","received_events_url":"https://api.github.com/users/jtomaszewski/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-04-18T17:22:44Z","updated_at":"2015-04-18T17:22:44Z","closed_at":null,"body":"This bug happens only on iOS.\r\n\r\nFor example if we have 10 alerts, and we'll assign them like this:\r\n\r\n```js\r\nvar ids = [1,2,3,4,5];\r\nfor (var i in ids) {\r\n  cordova.plugins.notification.local.schedule({id: ids[i]});\r\n}\r\n```\r\n\r\nThen only one of them will actually be assigned, propably because of some race condition.\r\n\r\nTo solve this, we need to:\r\n\r\n```js\r\n// wait with some callback/promise after adding the previous callback:\r\nvar ids = [1,2,3,4,5];\r\nvar i = 0;\r\ncallback(0);\r\n\r\nfunction callback(i) {\r\n  if (i >= ids.length) return;\r\n  cordova.plugins.notification.local.schedule({id: ids[i]}, function(){ callback(i+1) });\r\n}\r\n\r\n// OR\r\n// assign them all at once\r\ncordova.plugins.notification.local.schedule(ids.map(function(i){\r\n  return {id: i};\r\n}));\r\n```\r\n\r\nBut seems like there is no information in doc that we need to do this in this way! That's why I was fighting with this bug (which happens only on iOS) for a couple of days, wondering why only some of my notifications are actually being added."}}