コード例 #1
0
    private void Run()
    {
        Debug.Log("Example 6 - Per Record Progress");

        database = CKContainer.DefaultContainer().PrivateCloudDatabase;

        // Let's create 5 files at 1MB a piece
        // So we have enough data to see some upload progress

        // BTW CloudKit recommends that if your data exceeds 1MB you should put
        // it inside a CKAsset

        for (int i = 0; i < numFiles; i++)
        {
            var    record = new CKRecord("BigFile");
            byte[] bytes  = new byte[1000000];
            record.SetBuffer(bytes, "bytes");

            records[i] = record;
        }

        var op = new CKModifyRecordsOperation(records, null);

        op.Configuration.QualityOfService = NSQualityOfService.UserInitiated;

        op.PerRecordProgressBlock       = OnPerRecordProgress;
        op.PerRecordCompletionBlock     = OnPerRecordComplete;
        op.ModifyRecordsCompletionBlock = OnRecordsSaved;

        database.AddOperation(op);
    }
コード例 #2
0
    // 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;
    }
コード例 #3
0
    void Run()
    {
        Debug.Log("Example 4 - CKAsset");
        database = CKContainer.DefaultContainer().PrivateCloudDatabase;

        var record = new CKRecord("MyType");

        // CloudKit recommends if your data is larger than 1MB that you store
        // it as an asset...
        // our example won't be anything close to 1MB, but it'll illustrate the
        // technique

#if UNITY_TVOS
        string path = Path.Combine(Application.temporaryCachePath, "Asset.bytes");
#else
        string path = Path.Combine(Application.persistentDataPath, "Asset.bytes");
#endif

        byte[] bytes = Encoding.ASCII.GetBytes("AssetData");
        File.WriteAllBytes(path, bytes);

        // Assets have to be files, so you pass it the filepath to something
        // in the user's data directory
        // the asset will be stored in cloudkit, with a URL for retrieval

        var fileurl = NSURL.FileURLWithPath(path);
        record.SetAsset(new CKAsset(fileurl), "MyAsset");

        database.SaveRecord(record, OnRecordSaved);
    }
コード例 #4
0
    void Run()
    {
        //var testDisposable = new TestDisposable();

        //Debug.Log("made dispasable: " + testDisposable);

        //StartCoroutine(WaitABit());
        var op = new CKModifyRecordsOperation(null, new CKRecordID[] {
            new CKRecordID("1CB545B1-7CA3-423E-A215-67DA56578270"),
            new CKRecordID("321A8AD3-0FA9-40C3-8D76-D76328A0A7F1")
        });

        database = CKContainer.DefaultContainer().PrivateCloudDatabase;

        Debug.Log("Setting callback");
        op.ModifyRecordsCompletionBlock = (records, recordIds, error) =>
        {
            Debug.Log("Modify records done");
        };

        //Debug.Log("Setting QoS");
        op.Configuration.QualityOfService = NSQualityOfService.Default;

        database.AddOperation(op);

        StartCoroutine(WaitABit());
    }
コード例 #5
0
    private void CreateSubscription()
    {
        var database  = CKContainer.DefaultContainer().PrivateCloudDatabase;
        var predicate = NSPredicate.PredicateWithValue(true);

        var notificationInfo = new CKNotificationInfo();

        var querySubscription = new CKQuerySubscription(
            recordType,
            predicate,
            CKQuerySubscriptionOptions.FiresOnRecordCreation |
            CKQuerySubscriptionOptions.FiresOnRecordDeletion |
            CKQuerySubscriptionOptions.FiresOnRecordUpdate);

        querySubscription.NotificationInfo = notificationInfo;

        database.SaveSubscription(querySubscription, OnSubscriptionSaved);

        //alternatively...you can use a CKModifySubscriptionsOperation

        //var op = new CKModifySubscriptionsOperation(new[] { querySubscription }, null);
        //op.Configuration.QualityOfService = NSQualityOfService.UserInitiated;
        //op.ModifySubscriptionsCompletionBlock = OnSubscriptionModified;
        //database.AddOperation(op);
    }
コード例 #6
0
    public void Database_has_correct_scope(
        [Values(CKDatabaseScope.Private, CKDatabaseScope.Public, CKDatabaseScope.Shared)]
        CKDatabaseScope scope)
    {
        var database = CKContainer.DefaultContainer().DatabaseWithDatabaseScope(scope);

        Assert.AreEqual(database.DatabaseScope, scope);
    }
コード例 #7
0
    private void Run()
    {
        Debug.Log("Example 3 - Querying");
        database = CKContainer.DefaultContainer().PrivateCloudDatabase;

        // We need a bunch of records to search through
        names = new string[] {
            "Alice",
            "Bob",
            "Charles",
            "Danni",
            "Exavier"
        };

        // Make an array of CKRecords and set the name field to each of the
        // names in the array above...
        //
        recordsToSearch = names.Select(name => {
            var record = new CKRecord("Person");
            record.SetString(name, "name");
            return(record);
        }).ToArray();

        // CloudKit uses a CKModifyRecrodsOperation for both saving and deleting
        // (which is sorta wierd). The first parameter is records to save, the
        // second is record id's to delete
        //
        Debug.Log("Creating records");
        CKModifyRecordsOperation op = new CKModifyRecordsOperation(
            recordsToSearch,
            null
            );

        // Important to set quality of service to UserInitiated or cloudkit
        // may run your query a LONG time from now. Like minutes from now
        // (seriously). The default value of NSQualityOfServiceUtility is insane
        // You can read more about QoS here:
        // https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/PrioritizeWorkWithQoS.html
        op.Configuration.QualityOfService = NSQualityOfService.UserInitiated;

        // The modify records completion block is a callback function that's
        // invoked when the operation is complete
        op.ModifyRecordsCompletionBlock = OnRecordsSaved;

        database.AddOperation(op);

        var op2 = new CKFetchRecordsOperation(recordsToSearch.Select(x => x.RecordID).ToArray());

        op2.FetchRecordsCompletionHandler = (dictionary, error) =>
        {
            Debug.Log("Fetch records complete");
            //foreach (var kvp in dictionary)
            //{
            //    Debug.Log(string.Format("key:{0} value:{1}", kvp.Key.RecordName, kvp.Value));
            //}
        };
        database.AddOperation(op2);
    }
コード例 #8
0
    public void Can_add_operation()
    {
        var op       = new CKModifyRecordsOperation();
        var database = CKContainer.DefaultContainer().PrivateCloudDatabase;

        TestDelegate sut = () => database.AddOperation(op);

        Assert.DoesNotThrow(sut);
    }
コード例 #9
0
    public void Added_operation_sets_container_property()
    {
        var op        = new CKDiscoverUserIdentitiesOperation();
        var container = CKContainer.DefaultContainer();

        container.AddOperation(op);

        Assert.AreEqual(op.Configuration.Container, container);
    }
コード例 #10
0
    public void Adding_operation_sets_datbase_property_on_operation()
    {
        var op       = new CKModifyRecordsOperation();
        var database = CKContainer.DefaultContainer().PrivateCloudDatabase;

        database.AddOperation(op);

        Assert.AreEqual(op.Database, database);
    }
コード例 #11
0
 private void AccountStatusChanged(NSNotification obj)
 {
     // There's nothing useful in the NSNotification instance on the objective-c
     // side. Apple now wants you to check the account status seperately using
     // this call...
     // Getting the account status as an asyncronous call, with the potential
     // for an error.
     Debug.Log("CKContainer account status changed notification. Fetching account status...");
     CKContainer.DefaultContainer().AccountStatusWithCompletionHandler(OnAccountStatusComplete);
 }
コード例 #12
0
    private void Run()
    {
        Debug.Log("Example 5 - Zones");

        // Apple arcade recommends using zones for different GC users
        customZone = new CKRecordZone("GameCenterUser1");
        database   = CKContainer.DefaultContainer().PrivateCloudDatabase;

        database.SaveRecordZone(customZone, OnRecordZoneCreated);
    }
コード例 #13
0
    public void Can_retrieve_container_by_identifier()
    {
        var defaultContainer = CKContainer.DefaultContainer();
        var identifier       = defaultContainer.ContainerIdentifier;
        var otherContainer   = CKContainer.ContainerWithIdentifier(identifier);

        Assert.AreEqual(identifier, otherContainer.ContainerIdentifier);

        //These are not the same object?
        //Assert.AreEqual(defaultContainer, otherContainer);
    }
コード例 #14
0
    public IEnumerator Can_fetch_all_long_lived_operationIDs()
    {
        var wasCalled = false;

        CKContainer.DefaultContainer().FetchAllLongLivedOperationIDsWithCompletionHandler((operationIds, error) => {
            wasCalled = true;
        });

        yield return(WaitUntilWithTimeout(() => wasCalled, DefaultTimeout));

        Assert.IsTrue(wasCalled);
    }
コード例 #15
0
    public IEnumerator Can_get_account_status()
    {
        var wasCalled = false;

        CKContainer.DefaultContainer().AccountStatusWithCompletionHandler((status, error) => {
            wasCalled = true;
        });

        yield return(WaitUntilWithTimeout(() => wasCalled, DefaultTimeout));

        Assert.IsTrue(wasCalled);
    }
コード例 #16
0
    public IEnumerator Can_request_application_permission()
    {
        var wasCalled = false;

        CKContainer.DefaultContainer().RequestApplicationPermission(CKApplicationPermissions.UserDiscoverability, (status, error) => {
            wasCalled = true;
        });

        yield return(WaitUntilWithTimeout(() => wasCalled, DefaultTimeout));

        Assert.IsTrue(wasCalled);
    }
コード例 #17
0
    private void Run()
    {
        Debug.Log("Example1 - Hello World");

        database = CKContainer.DefaultContainer().PrivateCloudDatabase;

        var record = new CKRecord("Hello");

        record.SetString("Hello World", "Greeting");

        database.SaveRecord(record, OnRecordSaved);
    }
コード例 #18
0
    private void Run()
    {
        Debug.Log("Example 2 - Basic Database Operations");

        database = CKContainer.DefaultContainer().PrivateCloudDatabase;

        record = new CKRecord("MyType");
        record.SetString("An Example", "MyField");

        Debug.Log("Saving a record");
        database.SaveRecord(record, OnRecordSaved);
    }
コード例 #19
0
    public IEnumerator Can_fetch_share_participant_with_phone_number()
    {
        var number    = "1-800-888-8888";
        var wasCalled = false;

        CKContainer.DefaultContainer().FetchShareParticipantWithPhoneNumber(number, (participant, error) => {
            wasCalled = true;
        });

        yield return(WaitUntilWithTimeout(() => wasCalled, DefaultTimeout));

        Assert.IsTrue(wasCalled);
    }
コード例 #20
0
    public IEnumerator Can_fetch_long_lived_operation_by_operation_id()
    {
        var operationId = "operationId";
        var wasCalled   = false;

        CKContainer.DefaultContainer().FetchLongLivedOperationWithID(operationId, (operation, error) => {
            wasCalled = true;
        });

        yield return(WaitUntilWithTimeout(() => wasCalled, DefaultTimeout));

        Assert.IsTrue(wasCalled);
    }
コード例 #21
0
    public IEnumerator Can_fetch_all_record_zones()
    {
        var database  = CKContainer.DefaultContainer().PrivateCloudDatabase;
        var wasCalled = false;

        database.FetchAllRecordZonesWithCompletionHandler((zones, error) => {
            wasCalled = true;
        });

        yield return(WaitUntilWithTimeout(() => wasCalled, DefaultTimeout));

        Assert.IsTrue(wasCalled);
    }
コード例 #22
0
    public IEnumerator Can_fetch_share_metadata_by_URL()
    {
        var url       = NSURL.URLWithString("http://www.hovelhouse.com");
        var wasCalled = false;

        CKContainer.DefaultContainer().FetchShareMetadataWithURL(url, (shareMetadata, error) => {
            wasCalled = true;
        });

        yield return(WaitUntilWithTimeout(() => wasCalled, DefaultTimeout));

        Assert.IsTrue(wasCalled);
    }
コード例 #23
0
    public IEnumerator Can_save_subscription()
    {
        var            database           = CKContainer.DefaultContainer().PrivateCloudDatabase;
        var            wasCalled          = false;
        CKSubscription subscriptionToSave = null;

        database.SaveSubscription(subscriptionToSave, (sub, error) => {
        });

        yield return(WaitUntilWithTimeout(() => wasCalled, DefaultTimeout));

        Assert.IsTrue(wasCalled);
    }
コード例 #24
0
    public IEnumerator Can_fetch_subscription_by_its_id()
    {
        var database  = CKContainer.DefaultContainer().PrivateCloudDatabase;
        var wasCalled = false;

        database.FetchSubscriptionWithID("subid", (subscription, error) => {
            wasCalled = true;
        });

        yield return(WaitUntilWithTimeout(() => wasCalled, DefaultTimeout));

        Assert.IsTrue(wasCalled);
    }
コード例 #25
0
    public IEnumerator Can_discover_user_identity_with_email_address()
    {
        var email     = "*****@*****.**";
        var wasCalled = false;

        CKContainer.DefaultContainer().DiscoverUserIdentityWithEmailAddress(email, (identity, error) => {
            wasCalled = true;
        });

        yield return(WaitUntilWithTimeout(() => wasCalled, DefaultTimeout));

        Assert.IsTrue(wasCalled);
    }
コード例 #26
0
    public IEnumerator Can_fetch_share_participant_with_email_address()
    {
        var email     = "*****@*****.**";
        var wasCalled = false;

        CKContainer.DefaultContainer().FetchShareParticipantWithEmailAddress(email, (participant, error) => {
            wasCalled = true;
        });

        yield return(WaitUntilWithTimeout(() => wasCalled, DefaultTimeout));

        Assert.IsTrue(wasCalled);
    }
コード例 #27
0
    public IEnumerator Can_fetch_share_participant_with_user_recordID()
    {
        var recordId  = new CKRecordID("recordName");
        var wasCalled = false;

        CKContainer.DefaultContainer().FetchShareParticipantWithUserRecordID(recordId, (participant, error) => {
            wasCalled = true;
        });

        yield return(WaitUntilWithTimeout(() => wasCalled, DefaultTimeout));

        Assert.IsTrue(wasCalled);
    }
コード例 #28
0
    public IEnumerator Can_fetch_a_record()
    {
        var database  = CKContainer.DefaultContainer().PrivateCloudDatabase;
        var wasCalled = false;

        database.FetchRecordWithID(new CKRecordID("somerecordId"), (record, error) =>
        {
            wasCalled = true;
        });

        yield return(WaitUntilWithTimeout(() => wasCalled, DefaultTimeout));

        Assert.IsTrue(wasCalled);
    }
コード例 #29
0
    public IEnumerator Can_get_status_for_application_permission()
    {
        var wasCalled = false;

        var permission = CKApplicationPermissions.UserDiscoverability;

        CKContainer.DefaultContainer().StatusForApplicationPermission(permission, (status, error) => {
            wasCalled = true;
        });

        yield return(WaitUntilWithTimeout(() => wasCalled, DefaultTimeout));

        Assert.IsTrue(wasCalled);
    }
コード例 #30
0
    public IEnumerator Can_delete_subscription_by_its_id()
    {
        var            database           = CKContainer.DefaultContainer().PrivateCloudDatabase;
        var            wasCalled          = false;
        CKSubscription subscriptionToSave = null;

        database.DeleteSubscriptionWithID(subscriptionToSave.SubscriptionID, (sub, error) => {
            wasCalled = true;
        });

        yield return(WaitUntilWithTimeout(() => wasCalled, DefaultTimeout));

        Assert.IsTrue(wasCalled);
    }