Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCloud/iCloud Example/iCloud Example
Function:
Required plugins for this example: MBS MacBase Plugin, MBS MacCloud Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCloud/iCloud Example/iCloud Example
This example is the version from Sat, 12th Jan 2018.
Project "iCloud Example.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() if TargetMachO then if NSUbiquitousKeyValueStoreMBS.available = false then MsgBox "Please run only on Mac OS X 10.7" elseif DebugBuild then MsgBox "Please build app and sign it, before running it." end if else MsgBox "This example requires Mac OS X 10.7" end if End EventHandler
End Class
Class MainWindow Inherits Window
Const ContainerID = "iCloud.de.monkeybreadsoftware.testing"
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
Control OpenFolderButton Inherits PushButton
ControlInstance OpenFolderButton Inherits PushButton
EventHandler Sub Action() dim n as new NSFileManagerMBS dim s as FolderItem = n.FileForUbiquityContainerIdentifier(ContainerID) if s = nil then MsgBox "Failed." else s.Launch end if End EventHandler
End Control
Control PutButton Inherits PushButton
ControlInstance PutButton Inherits PushButton
EventHandler Sub Action() // create a file dim p as Picture = LogoMBS(500) dim file as FolderItem = SpecialFolder.Temporary.Child("test.jpg") p.Save(file, p.SaveAsJPEG, p.QualityHigh) // make ubiquious dim name as string = "test.jpg" list.AddRow "Upload file "+name dim n as new NSFileManagerMBS dim URL as string = n.URLForUbiquityContainerIdentifier(ContainerID) dim NewURL as string = n.URLByAppendingPathComponent(URL, name) list.AddRow "Base URL: "+URL list.AddRow "File URL: "+NewURL dim error as NSErrorMBS if n.setUbiquitous(true, file, newurl, error) then list.AddRow "OK" else list.AddRow "Error: "+error.localizedDescription end if End EventHandler
End Control
Control QueryFiles Inherits PushButton
ControlInstance QueryFiles Inherits PushButton
EventHandler Sub Action() query = new MyNSMetadataQueryMBS dim paths() as string paths.Append query.NSMetadataQueryUbiquitousDataScope 'paths.Append query.NSMetadataQueryUbiquitousDocumentsScope query.setSearchScopes paths // dummy predicate to find all items dim args() as Variant args.Append NSMetadataItemMBS.NSMetadataItemFSNameKey dim pred as NSPredicateMBS = NSPredicateMBS.predicateWithFormat("%K LIKE '*'", args) query.predicate = pred if query.startQuery then // will call events for results else MsgBox "failed to query." end if End EventHandler
End Control
Control PublishButton Inherits PushButton
ControlInstance PublishButton Inherits PushButton
EventHandler Sub Action() // get download url which people can use for sending it in email to share file with others dim n as new NSFileManagerMBS dim URL as string = n.URLForUbiquityContainerIdentifier(ContainerID) dim NewURL as string = n.URLByAppendingPathComponent(URL, "test.jpg") list.AddRow "File URL: "+NewURL List.AddRow "Is in iCloud: "+str(n.isUbiquitousItem(NewURL)) dim error as NSErrorMBS dim d as date dim publishingURL as string = n.URLForPublishingUbiquitousItem(newURL, d, error) if error <> nil then list.AddRow "Error: "+error.localizedDescription else list.AddRow "PublishingURL: "+publishingURL if d<>Nil then List.AddRow "Expiration date: "+d.longdate end if End EventHandler
End Control
EventHandler Sub Open() // Let's test key value store for storing preferences synced between different dim u as NSUbiquitousKeyValueStoreMBS = NSUbiquitousKeyValueStoreMBS.defaultStore // on second launch, we should have right value List.AddRow "Value for test key: "+u.StringValue("testing") List.AddRow "This is "+str(u.IntegerValue("counter"))+"th launch" u.StringValue("testing") = "Hello World" u.IntegerValue("counter") = u.IntegerValue("counter") + 1 call u.synchronize End EventHandler
Property query As MyNSMetadataQueryMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyNSMetadataQueryMBS Inherits NSMetadataQueryMBS
EventHandler Sub DidFinishGathering(n as NSNotificationMBS) me.disableUpdates // got some data dim list as listbox = MainWindow.List List.AddRow "Search finished." dim items() as NSMetadataItemMBS = me.results List.AddRow str(UBound(items)+1)+" items found" for each item as NSMetadataItemMBS in items list.AddRow item.DisplayName+", "+item.FileName+", "+str(item.FileSize/1000, "0")+" KB" next End EventHandler
EventHandler Sub DidStartGathering(n as NSNotificationMBS) // search started MainWindow.List.AddRow "Search started." End EventHandler
End Class
End Project

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacCloud Plugin.




Links
MBS Xojo PDF Plugins