iOS Question iCloud KVS support?

keirS

Well-Known Member
Licensed User
Longtime User
Searched for this but couldn't find anything so I guess it's not available? Is it possible implement it using NativeObject or would it require knowledge of Objective-C?
 

BillMeyer

Well-Known Member
Licensed User
Longtime User
Exactly what are you trying achieve - is it CloudKVS ?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I also first thought that you are asking about CloudKVS which is available in B4i: https://www.b4x.com/android/forum/threads/b4x-cloudkvs-synchronized-key-value-store.63536/

iCloud KVS:

1. Create an explicit App Id and enable iCloud:

SS-2018-03-07_18.28.58.png


2. Download a provision profile based on this app id.

3. Find the prefix of this app id:

SS-2018-03-07_18.29.44.png


4. Add to your code:
B4X:
#Entitlement: <key>com.apple.developer.ubiquity-kvstore-identifier</key><string>2Z8J7LMQ63.b4i.myapplication</string>
Change the prefix and the package name.

5. Process global:
B4X:
Private iCloudKVS As NativeObject

6. App_Start:
B4X:
iCloudKVS = iCloudKVS.Initialize("NSUbiquitousKeyValueStore").GetField("defaultStore")

7.
B4X:
Public Sub PutMapInCloud(Key As String, m As Map)
   iCloudKVS.RunMethod("setDictionary:forKey:", Array(m.ToDictionary, Key))
   Log("synchronize result: "  & iCloudKVS.RunMethod("synchronize", Null).AsBoolean)
End Sub

Public Sub GetMapFromCloud (Key As String) As Map
   Dim dict As Object = iCloudKVS.RunMethod("dictionaryForKey:", Array(Key))
   If dict = Null Then
       Dim res As Map
       Return res 'will be uninitialized
   End If
   Dim B4IMap As NativeObject
   Return B4IMap.Initialize("B4IMap").RunMethod("convertToMap:", Array(dict))
End Sub

With these two subs you can put a map in the cloud and get it back.
The map should hold primitive keys and values.
 
Upvote 0
Top