NSUbiquityIdentityDidChangeNotification和SIGKILL [英] NSUbiquityIdentityDidChangeNotification and SIGKILL

查看:70
本文介绍了NSUbiquityIdentityDidChangeNotification和SIGKILL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

迅捷1.2 Xcode 6

长时间收听者,首次呼叫者.

你好

直接从马口中说:要处理iCloud可用性的变化,请注册以接收NSUbiquityIdentityDidChangeNotification通知.

这是他们提供的实现此目的的代码:

[[NSNotificationCenter defaultCenter]

addObserver: self

   selector: @selector (iCloudAccountAvailabilityChanged:)

       name: NSUbiquityIdentityDidChangeNotification

     object: nil];

我在应用程序中将其快速化为:

var observer = NSNotificationCenter.defaultCenter().addObserverForName
(NSUbiquityIdentityDidChangeNotification, object: nil, queue: NSOperationQueue.mainQueue()
){...completion block...}

src:解决方案

简短回答

要在用户使用应用程序登录或注销iCloud时在iOS中收到通知,请使用CKAccountChangedNotification,而不是NSUbiquityIdentityChanged.

长答案

我一直在努力使它也能正常工作.我记得在WWDC16的一次谈话中,有一些他们建议使用的类似.但是,从他们提供的示例代码中,我只能找到NSUbiquityKeyIdentityChanged,而我还没有开始工作.

所以我回到了视频(从2015年开始).那是我看到他们引用的CKAccountChangedNotification的地方-完全按预期工作:

  • 从Xcode在模拟器上启动您的应用
  • 退出模拟器上的设置"应用
  • 登录(或注销)iCloud帐户
  • 返回到您的应用(模拟器主屏幕上的点击图标)
    • 收到通知.
  • 再次退出设置"应用
  • 注销(或登录)到iCloud帐户
  • 再次返回您的应用
    • 收到另一个通知.

Swift 1.2 Xcode 6

Long-time listener, first-time caller.

Hello,

Straight from the horse's mouth: "To handle changes in iCloud availability, register to receive the NSUbiquityIdentityDidChangeNotification notification."

Here is the code they provide to implement this:

[[NSNotificationCenter defaultCenter]

addObserver: self

   selector: @selector (iCloudAccountAvailabilityChanged:)

       name: NSUbiquityIdentityDidChangeNotification

     object: nil];

I Swiftified it in my app to:

var observer = NSNotificationCenter.defaultCenter().addObserverForName
(NSUbiquityIdentityDidChangeNotification, object: nil, queue: NSOperationQueue.mainQueue()
){...completion block...}

src: https://developer.apple.com/library/ios/documentation/General/Conceptual/iCloudDesignGuide/Chapters/iCloudFundametals.html#//apple_ref/doc/uid/TP40012094-CH6-SW6

What is the correct way to implement this? Does it go in the AppDelegate? Do we remove the observer when the app gets sent to the background?

The problem I'm encountering is that when the Ubiquity Token changes, the app is terminated anyway because the user has changed iCloud settings.

How do you all manage to subscribe to this notification, and, if you don't, what do you do instead to keep track of the current logged in iCloud user?

Thank you!

解决方案

Short Answer

To be notified in iOS when a user logs in or out of iCloud while using your app, use CKAccountChangedNotification, not NSUbiquityIdentityChanged.

Long Answer

I've been trying to get this to work as well. I remembered something from one of the talks at WWDC16 that there was something like this that they recommended to use. However, from the sample code they provide, I've only been able to find NSUbiquityKeyIdentityChanged, which I haven't been able to get to work.

So I went back to the video (it's from 2015). That's where I saw them refer to CKAccountChangedNotification – and it works exactly as expected:

  • Launch your app on the simulator from Xcode
  • Exit to the Settings app on the simulator
  • Log in (or out) of iCloud account
  • Go back into your app (tap icon on simulator home screen)
    • A notification is received.
  • Exit to Settings app again
  • Log back out (or in) to iCloud account
  • Go back into your app again
    • Another notification is received.

这篇关于NSUbiquityIdentityDidChangeNotification和SIGKILL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆