ios - NSUbiquityIdentityDidChangeNotification and SIGKILL -
swift 1.2 xcode 6
long-time listener, first-time caller.
hello,
straight horse's mouth: "to handle changes in icloud availability, register receive nsubiquityidentitydidchangenotification notification."
here code provide implement this:
[[nsnotificationcenter defaultcenter] addobserver: self selector: @selector (icloudaccountavailabilitychanged:) name: nsubiquityidentitydidchangenotification object: nil];
i swiftified in app to:
var observer = nsnotificationcenter.defaultcenter().addobserverforname (nsubiquityidentitydidchangenotification, object: nil, queue: nsoperationqueue.mainqueue() ){...completion block...}
what correct way implement this? go in appdelegate? remove observer when app gets sent background?
the problem i'm encountering when ubiquity token changes, app terminated anyway because user has changed icloud settings.
how manage subscribe notification, and, if don't, do instead keep track of current logged in icloud user?
thank you!
short answer
to notified in ios when user logs in or out of icloud while using app, use ckaccountchangednotification
, not nsubiquityidentitychanged
.
long answer
i've been trying work well. remembered 1 of talks @ wwdc16 there something recommended use. however, sample code provide, i've been able find nsubiquitykeyidentitychanged
, haven't been able work.
so went the video (it's 2015). that's saw them refer ckaccountchangednotification
– , works expected:
- launch app on simulator xcode
- exit settings app on simulator
- log in (or out) of icloud account
- go app (tap icon on simulator home screen)
- a notification received.
- exit settings app again
- log out (or in) icloud account
- go app again
- another notification received.