-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·491 lines (469 loc) · 25.2 KB
/
index.html
File metadata and controls
executable file
·491 lines (469 loc) · 25.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
<!--
Copyright (C) 2016-2022 Apple Inc. All Rights Reserved.
See LICENSE.txt for this sample’s licensing information
Abstract:
The main HTML file of the CloudKit Catalog sample app.
Purpose:
Replace the outdated source files on Apple Developer Archive.
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CloudKit Catalog V2</title>
<meta name="description" content="Getting started with CloudKit JS V2" />
<link rel="stylesheet" href="css/cloudkit-catalog.css">
</head>
<body>
<div id="main" class="main-pane">
<div class="background-strip"></div>
<div class="left-pane" id="left-pane">
<div class="home">
<div class="icon" id="home-icon"></div>
<div class="toggle-buttons">
<div class="expand-button left-pane-toggle-button" id="expand-left-column">〉</div>
<div class="contract-button left-pane-toggle-button hide" id="contract-left-column">〈</div>
</div>
<div class="mask"></div>
</div>
<div class="left-bar-wrapper">
<div class="vertical-scroll-container">
<div class="menu-items">
<div class="menu-item-container readme">
<div class="border"></div>
<a class="menu-item" href="#readme" title="README">
<div class="icon"></div>
<div class="name"><img height="12"
src="https://img.shields.io/badge/-OK-success?style=flat&logo=checkmarx&logoColor=white"
alt="OK"> Get Started</div>
</a>
</div>
<div class="menu-item-container authentication">
<div class="border"></div>
<a class="menu-item" href="#authentication" title="Authentication">
<div class="icon"></div>
<div class="name"><img height="12"
src="https://img.shields.io/badge/-OK-success?style=flat&logo=checkmarx&logoColor=white"
alt="OK"> Authentication</div>
</a>
</div>
<div class="menu-item-container discoverability">
<div class="border"></div>
<a class="menu-item" href="#discoverability" title="Discoverability">
<div class="icon"></div>
<div class="name"><img height="12"
src="https://img.shields.io/badge/-OK-success?style=flat&logo=checkmarx&logoColor=white"
alt="OK"> Discoverability</div>
</a>
</div>
<div class="menu-item-container public-query">
<div class="border"></div>
<a class="menu-item" href="#public-query" title="Query">
<div class="icon"></div>
<div class="name"><img height="12"
src="https://img.shields.io/badge/-OK-success?style=flat&logo=checkmarx&logoColor=white"
alt="OK"> Query</div>
</a>
</div>
<div class="menu-item-container private-zones">
<div class="border"></div>
<a class="menu-item" href="#private-zones" title="Zones">
<div class="icon"></div>
<div class="name"><img height="12"
src="https://img.shields.io/badge/-OK-success?style=flat&logo=checkmarx&logoColor=white"
alt="OK"> Zones</div>
</a>
</div>
<div class="menu-item-container private-records">
<div class="border"></div>
<a class="menu-item" href="#private-records" title="Records">
<div class="icon"></div>
<div class="name"><img height="12"
src="https://img.shields.io/badge/-OK-success?style=flat&logo=checkmarx&logoColor=white"
alt="OK"> Records</div>
</a>
</div>
<!-- <div class="menu-item-container private-sync">
<div class="border"></div>
<a class="menu-item" href="#private-sync" title="Sync">
<div class="icon"></div>
<div class="name"><img height="12"
src="https://img.shields.io/badge/-Pull_Request_to_Contribute-red?style=flat&logo=ifixit&logoColor=white"
alt="NOT_OK"> Sync</div>
</a>
</div> -->
<div class="menu-item-container private-subscriptions">
<div class="border"></div>
<a class="menu-item" href="#private-subscriptions" title="Subscriptions">
<div class="icon"></div>
<div class="name"><img height="12"
src="https://img.shields.io/badge/-OK-success?style=flat&logo=checkmarx&logoColor=white"
alt="OK"> Subscriptions</div>
</a>
</div>
<div class="menu-item-container notifications">
<div class="border"></div>
<a class="menu-item" href="#notifications" title="Notifications">
<div class="icon"></div>
<div class="name with-subtitle"><img height="12"
src="https://img.shields.io/badge/-OK-success?style=flat&logo=checkmarx&logoColor=white"
alt="OK"> Notifications</div>
<div class="subtitle" id="connected-text">Disconnected (Run first)</div>
<div class="alert hide">
<div id="number-of-alerts" class="alert-text">0</div>
</div>
</a>
</div>
</div>
</div>
<a class="menu-item documentation" href="https://developer.apple.com/documentation/cloudkitjs"
target="_blank" title="Documentation">
<div class="icon"></div>
<div class="name"><img width="30"
src="https://img.shields.io/badge/-NEW-informational?style=flat&logo=apple&logoColor=white"
alt="Docs"> Documentation</div>
</a>
</div>
</div>
<div class="right-pane">
<div class="header">
<div class="left-button disabled">
<div class="play-icon"></div>
<button id="run-button" class="link" disabled>One-click Run Code</button>
</div>
<a href="#authentication">
<span id="username"></span>
</a>
</div>
<div class="alert-bar alert-showing" id="config-bar">
<span class="config-key">Container:</span>
<span class="config-value" id="config-container">iCloud.io.startway.CloudKitCatalog</span>
<span class="config-key">Environment:</span>
<span class="config-value" id="config-environment">Development</span>
</div>
<div class="vertical-scroll-container">
<div class="page" id="page">
<div class="page-segments"></div>
</div>
</div>
</div>
</div>
<div id="dialog" class="hide">
<div id="dialog-veil"></div>
<div id="dialog-text"></div>
</div>
<div class="hide">
<div id="authentication">
<div class="description">
<h4>Class: Container</h4>
<h1>.setUpAuth()</h1>
<p>This sample demonstrates how to authenticate a user with your app.
There are two steps to authentication:</p>
<ol>
<li><b>Setting up auth.</b> This step checks whether a user is signed in. If you have specified
<code>auth.persist = true</code> in your configuration you could run <i>setUpAuth</i> while
bootstrapping
your app and this function will use the stored cookie. The promise resolves with a
<code>userInfo</code> object or
<code>null</code> and a sign-in or
sign-out button will have been appended to the button container with id
<code>apple-sign-in-button</code>
or <code>apple-sign-out-button</code> (whichever is appropriate).
These containers need to be in the DOM before executing the function and
their IDs can be customized in <code>CloudKit.configure</code>.
</li>
<li><b>Binding handlers to the rendered button.</b> The promises <code>whenUserSignsIn</code> and
<code>whenUserSignsOut</code>
are resolved when the user signs-in/out respectively. The former resolves with a
<code>userInfo</code> object.</li>
</ol>
</div>
</div>
<div id="discoverability">
<div class="description">
<h4>Class: Container</h4>
<h1>.fetchCurrentUserIdentity()</h1>
<p>This sample demonstrates how to fetch the currently signed-in user’s <code>userIdentity</code>
object. If the current user has made himself discoverable to the app, this object will have nonempty
<code>nameComponents.</code></p>
</div>
<div class="description">
<h4>Class: Container</h4>
<h1>.discoverAllContactUserInfos()</h1>
<p>This sample demonstrates how to obtain a list of <code>userInfo</code> objects corresponding to users
of the app
in the signed-in user’s iCloud Contacts who have made themselves discoverable to the app.</p>
</div>
<div class="description">
<h4>Class: Container</h4>
<h1>.discoverUserInfoWithEmailAddress()</h1>
<p>This sample demonstrates how to look up a discoverable user’s name by email address. This
method will
always return a <code>userInfo</code> object with the <code>emailAddress</code> field populated. The
other fields will be
populated only if a matching discoverable user is found.</p>
</div>
<div class="description">
<h4>Class: Container</h4>
<h1>.discoverUserInfoWithUserRecordName()</h1>
<p>This sample demonstrates how to look up a discoverable user’s info by userRecordName. The
<code>.catch()</code> block is invoked
when no matching user is found.</p>
</div>
</div>
<div id="not-found">
<div class="description">
<h1>Page Not Found</h1>
<p>The page you were looking for was not found. Please use the menu on the left to navigate the app.</p>
</div>
</div>
<div id="notifications">
<div class="description">
<h4>Class: Container</h4>
<h1>.registerForNotifications()</h1>
<p>This sample shows how to add a notification listener to the container. The listener will get called
whenever the server sends us a notification of an update to a subscription. In order to receive
notifications your app
must park a connection with the notification backend using <code>registerForNotifications</code>.
</p>
</div>
</div>
<div id="private-records">
<div class="description">
<h4>Class: Database</h4>
<h1>.saveRecords()</h1>
<p>This sample demonstrates how an authenticated user can save a record to his/her private database. Our
example
records are of type <b>Items</b>. Leave the recordName field blank to let the server generate a
record name. Leave the
recordChangeTag field blank when creating a new record and supply the latest server change tag when
modifying an existing
record.</p>
</div>
<div class="description">
<h4>Class: Database</h4>
<h1>.deleteRecords()</h1>
<p>This sample demonstrates how an authenticated user can delete a record from the private database.</p>
</div>
<div class="description">
<h4>Class: Database</h4>
<h1>.fetchRecords()</h1>
<p>This sample demonstrates how to fetch a record by record name from the private database.</p>
</div>
</div>
<div id="private-subscriptions">
<div class="description">
<h4>Class: Database</h4>
<h1>.saveSubscription()</h1>
<p>This sample demonstrates how a user can subscribe to a change to a record in a specific zone
(<i>zone subscription</i>) as well as to changes to records that match a query condition
(<i>query subscription</i>). Once subscribed, your app can register for <a
href="#notifications">notifications</a>
of changes.
</p>
</div>
<div class="description">
<h4>Class: Database</h4>
<h1>.deleteSubscription()</h1>
<p>This sample shows how to delete a subscription by ID.</p>
</div>
<div class="description">
<h4>Class: Database</h4>
<h1>.fetchSubscription()</h1>
<p>This sample shows how to fetch a subscription by ID.</p>
</div>
<div class="description">
<h4>Class: Database</h4>
<h1>.fetchAllSubscriptions()</h1>
<p>This sample shows how to fetch all subscriptions.</p>
</div>
</div>
<div id="private-sync">
<div class="description">
<h4>Class: Database</h4>
<h1>.fetchChangedRecords()</h1>
<p>This sample demonstrates how an authenticated user can get all changes relative to a sync token in a
custom zone.
If no sync token is provided all records in the zone are returned. The response will always contain
a new sync token
which can be cached in the client and sent in a new sync request. The sync token can also be used
for paginating a result
set. The <code>moreComing</code> boolean on the response indicates if the result set is incomplete.
</p>
<p>When you have a zone-level <a href="#private-subscriptions">subscription</a> you can get
<a href="#notifications">notified</a> of changes to that zone and you would typically run
<code>fetchChangedRecords</code>
to then fetch the latest changes and bring your client up-to-date.
</p>
</div>
</div>
<div id="private-zones">
<div class="description">
<h4>Class: Database</h4>
<h1>.saveRecordZone()</h1>
<p>This sample shows how to create a custom zone in the user’s private database. Zones are useful
for
syncing a user’s data. Once you have created a custom zone you will be able to
<a href="#private-records">create records</a> in that zone and test the <a
href="#private-sync">sync</a> feature.
</p>
</div>
<div class="description">
<h4>Class: Database</h4>
<h1>.deleteRecordZone()</h1>
<p>This sample shows how to delete a custom zone by name from the private database.</p>
</div>
<div class="description">
<h4>Class: Database</h4>
<h1>.fetchRecordZone()</h1>
<p>This sample shows how to fetch a record zone by name from the private database.</p>
</div>
<div class="description">
<h4>Class: Database</h4>
<h1>.fetchAllRecordZones()</h1>
<p>This sample shows how to list all record zones in your private database. The response will always
contain the default zone.</p>
</div>
</div>
<div id="public-query">
<div class="description">
<h4>Class: Database</h4>
<h1>.performQuery()</h1>
<p>This sample demonstrates how any user can query records in the public database. The same example will
work equally well for
querying records in a user’s private database. We will query records of type
<b>Items</b> which has the following schema:
</p>
<ul>
<li><b>name</b> : String</li>
<li><b>location</b> : Location</li>
<li><b>asset</b> : Asset</li>
</ul>
<p>Our code sample gets the client’s geolocation and asks for a list of Items sorted by closest
distance from this
location.</p>
</div>
</div>
<div id="readme">
<div class="description">
<img width="100%"
src="https://docs-assets.developer.apple.com/published/7d6e1981e8/31eae1d0-d238-4dad-a50e-e8c1fc276d81.png" />
<h1><b>Getting started with CloudKit JS V2</b></h1>
<p>This web application provides executable sample code for the core API methods provided by the
CloudKit JS
JavaScript library. While these methods cover many typical use cases, there are more flexible
versions
available if needed which allow for batch requests and more configuration. The user is advised to
refer to the
<a
href="https://developer.apple.com/library/prerelease/ios/documentation/CloudKitJS/Reference/CloudKitJavaScriptReference/index.html">CloudKit
JS Reference</a>
for more information.
</p>
<p>All code examples can be run by clicking the play button at the top of the page. The results will be
displayed below
the sample code block.</p>
<h2>Downloading and running CloudKit Catalog</h2>
<p>The static assets which make up this tutorial are available for download as a convenient zip package
from the
<a href="https://github.com/1998code/Apple-CloudKit-Catalog-V2">Github</a>.
The configuration code resides in the file <b>js/init.js</b>.
</p>
<pre><code>CloudKit.configure({
containers: [{
// Change this to a container identifier you own.
containerIdentifier: 'iCloud.io.startway.CloudKitCatalog',
apiTokenAuth: {
// And generate a web token through CloudKit Dashboard.
apiToken: '<Insert your API Token here>',
persist: true, // Sets a cookie.
signInButton: {
id: 'apple-sign-in-button',
theme: 'black' // Other options: 'white', 'white-with-outline'.
},
signOutButton: {
id: 'apple-sign-out-button',
theme: 'black'
}
},
environment: 'development'
}]
});</code></pre>
<p>Change the container identifier to one that you own.
For more information on how to create a container see <a
href="https://developer.apple.com/library/etc/redirect/ios_cloudkit_dashboard_guide">CloudKit
Quick Start</a>. Once you have a container, you will
need to create an <b>Items</b> record type with fields:</p>
<ul>
<li><b>name</b> : String</li>
<li><b>location</b> : Location</li>
<li><b>asset</b> : Asset</li>
</ul>
<p>You can do this as well as generate an API token through the
<a href="https://icloud.developer.apple.com/dashboard/">CloudKit Dashboard</a>.
</p>
<h2>Obtaining the CloudKit JS library</h2>
<p>CloudKit JS is hosted at
<a
href="https://cdn.apple-cloudkit.com/ck/2/cloudkit.js">https://cdn.apple-cloudkit.com/ck/2/cloudkit.js</a>.
Include the library on your web page using either of the two methods below. You will
automatically get updates and bug fixes as they are released.
</p>
<h3>Option #1 - Load CloudKit JS synchronously</h3>
<pre><code><script src="https://cdn.apple-cloudkit.com/ck/2/cloudkit.js"></script></code></pre>
<h3>Option #2 - Load CloudKit JS asynchronously</h3>
<pre><code><!-- Listen for the cloudkitloaded event on the window object. -->
<script>
window.addEventListener('cloudkitloaded', function() {
// Now the global namespace CloudKit is defined and you can proceed
// to configure your application.
});
</script>
<!-- Include the script with the ‘async’ attribute. -->
<script src="https://cdn.apple-cloudkit.com/ck/2/cloudkit.js" async></script></code></pre>
<h2>Browser support</h2>
<p>CloudKit JS is supported on Safari, Firefox, Chrome, Internet Explorer and Microsoft Edge, including
embedded web views.
For security reasons, a mobile web view must launch the Apple sign-in page in a native browser in
order
to use iCloud authentication.</p>
<br>
</div>
</div>
</div>
<script>
/*
* Initialize the global objects we will need.
*/
if (typeof CKCatalog === 'undefined') {
CKCatalog = {};
}
if (typeof CKCatalog.tabs === 'undefined') {
CKCatalog.tabs = {
'readme': [{}],
'not-found': [{}]
};
}
</script>
<script src="js/ui-utils/dialog.js"></script>
<script src="js/ui-utils/table.js"></script>
<script src="js/ui-utils/form.js"></script>
<script src="js/cloudkit-code-samples/authentication.js"></script>
<script src="js/cloudkit-code-samples/discoverability.js"></script>
<script src="js/cloudkit-code-samples/public-query.js"></script>
<script src="js/cloudkit-code-samples/private-zones.js"></script>
<script src="js/cloudkit-code-samples/private-records.js"></script>
<script src="js/cloudkit-code-samples/private-sync.js"></script>
<script src="js/cloudkit-code-samples/private-subscriptions.js"></script>
<script src="js/cloudkit-code-samples/notifications.js"></script>
<script src="js/ui-utils/tab-manager.js"></script>
<script src="js/init.js"></script>
<script async src="https://cdn.apple-cloudkit.com/cloudkit-catalog/highlight.pack.js"
onload="CKCatalog.tabManager.initializeCodeHighlighting()">
</script>
<script>
window.addEventListener('cloudkitloaded', CKCatalog.init);
</script>
<script async src="https://cdn.apple-cloudkit.com/ck/2/cloudkit.js"></script>
</body>
</html>