Platforms to show: All Mac Windows Linux Cross-Platform

/MacFrameworks/Handoff/Handoff Desktop


Last modified Thu, 24th Jul 2024.

You find this example project in your MBS Xojo Plugin download as a Xojo project file within the examples folder: /MacFrameworks/Handoff/Handoff Desktop

Download this example: Handoff Desktop.zip

Project "Handoff Desktop.xojo_binary_project"
Class App Inherits DesktopApplication
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Opening() End EventHandler
Sub Constructor() // we do this early to catch events early events = New NSUserActivityEvents End Sub
Property events As NSUserActivityEvents
End Class
Class MainWindow Inherits DesktopWindow
Control MyTextArea Inherits DesktopTextArea
ControlInstance MyTextArea Inherits DesktopTextArea
End Control
Control Info Inherits DesktopLabel
ControlInstance Info Inherits DesktopLabel
End Control
Control List Inherits DesktopListBox
ControlInstance List Inherits DesktopListBox
End Control
EventHandler Sub Opening() userActivity = New NSUserActivityMBS("de.monkeybreadsoftware.example.handoff") Dim d As New Dictionary d.Value("ComputerName") = SystemInformationMBS.ComputerName userActivity.title = "Example" userActivity.EligibleForHandoff = True userActivity.setRequiredUserInfoKeys Array("content") userActivity.userInfo = d userActivity.needsSave = True // use event to update this before sending. userActivity.becomeCurrent // attach this activity to the window NSUserActivityEvents.SetUserActivity(Self, userActivity) End EventHandler
Property userActivity As NSUserActivityMBS
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
MenuItem HelpMenu = "&Help"
End MenuBar
Sign
End Sign
Class NSUserActivityEvents Inherits NSUserActivityEventsMBS
EventHandler Function continueUserActivity(userActivity as NSUserActivityMBS) As Boolean // Tells the delegate that the data for continuing an activity is available. Log CurrentMethodName If userActivity.activityType = "de.monkeybreadsoftware.example.handoff" Then // we like this type return True End If End EventHandler
EventHandler Sub deletedAllSavedUserActivities() Log CurrentMethodName End EventHandler
EventHandler Sub deletedSavedUserActivities(persistentIdentifiers() as String) Log CurrentMethodName End EventHandler
EventHandler Sub didFailToContinueUserActivityWithType(userActivityType as String, error as NSErrorMBS) // Tells the delegate that the activity couldn’t be continued. Log CurrentMethodName If error <> Nil Then Log error.LocalizedDescription End If End EventHandler
EventHandler Sub didUpdateUserActivity(userActivity as NSUserActivityMBS) // Tells the delegate that the activity was updated. Log CurrentMethodName End EventHandler
EventHandler Sub gotContinuationStreams(userActivity as NSUserActivityMBS, inputStream as Variant, outputStream as Variant, error as NSErrorMBS) Log CurrentMethodName End EventHandler
EventHandler Sub restoreUserActivityState(userActivity as NSUserActivityMBS) // This event will be called from the main thread. Log CurrentMethodName If userActivity.activityType = "de.monkeybreadsoftware.example.handoff" Then Dim d As Dictionary = userActivity.userInfo MainWindow.MyTextArea.Text = d.Value("content") End If End EventHandler
EventHandler Sub updateUserActivityState(responder as Variant, userActivity as NSUserActivityMBS) Log CurrentMethodName End EventHandler
EventHandler Sub userActivityDidReceiveStreams(userActivity as NSUserActivityMBS, inputStream as Variant, outputStream as Variant) Log CurrentMethodName End EventHandler
EventHandler Sub userActivityWasContinued(userActivity as NSUserActivityMBS) Log CurrentMethodName End EventHandler
EventHandler Sub userActivityWillSave(userActivity as NSUserActivityMBS) Log CurrentMethodName If userActivity.activityType = "de.monkeybreadsoftware.example.handoff" Then // our one Dim d As New Dictionary d.Value("source") = "from Mac" d.Value("content") = MainWindow.MyTextArea.Text userActivity.addUserInfoEntries(d) 'userActivity.userInfo = d End If End EventHandler
EventHandler Function willContinueUserActivityWithType(userActivityType as String) As Boolean // Tells the delegate if your app takes responsibility for notifying users when a continuation activity takes longer than expected. Log CurrentMethodName // data is coming soon Return true // we handle GUI End EventHandler
Sub Log(s as string) System.DebugLog s MainWindow.List.AddRow s End Sub
End Class
ExternalFile info
End ExternalFile
End Project

Download this example: Handoff Desktop.zip

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


The biggest plugin in space...