// Start is called before the first frame update IEnumerator Start() { Debug.Log("Example 9 - Subscriptions"); Debug.Log("Requesting notification token"); ICloudNotifications.RequestNotificationToken((tokenBytes, error) => { if (error != null) { Debug.LogError("Failed to get push notification token: " + error.LocalizedDescription); } else { Debug.LogError("Got push notification token"); } }); ICloudNotifications.SetRemoteNotificationHandler((p) => { Debug.Log("remote notification handler called"); }); database = CKContainer.DefaultContainer().PrivateCloudDatabase; // You only need to register a subscription ONCE // So check that a subscription exists before trying to add one database.FetchAllSubscriptionsWithCompletionHandler(OnSubscriptionsFetched); ICloudNotifications.SetRemoteNotificationHandler(OnQueryNotification); yield break; }
private void Run() { Debug.Log("Example 7 - Account Status"); // This is the Core Foundation way of checking if the user has changed // This method is NOT recommended by apple. But is the only option if you // are not using CloudKit (and are just using key value storage) Token = NSFileManager.DefaultManager().UbiquityIdentityToken; Unsubscriber = ICloudNotifications.AddIdentityDidChangeObserver(OnCloudIdentityChanged); // If your using cloud kit...apple has this to say: // CloudKit clients should not use this token as a way to identify // whether the iCloud account is logged in. Instead, use // accountStatusWithCompletionHandler: or // fetchUserRecordIDWithCompletionHandler: // https://developer.apple.com/documentation/foundation/nsfilemanager/1408036-ubiquityidentitytoken?language=objc // This is the cloudkit way // Listen for the accountStatusChanged notification // Apple says... "Notification posted when the status of the signed-in iCloud account may have changed." // This notification will fire for a number of reasons, not all of them will be related to signing in or // out of iCloud. For instance, toggling the iCloud Drive permission in iCloud settings will cause this // to fire CKContainer.AddAccountChangedNotificationObserver(AccountStatusChanged); // At this point you should sign in or out of iCloud to update the account stauts. Debug.Log("Account status notification handlers attached. Sign in or out of iCloud ot update."); Debug.Log("Waiting for change in account status..."); }