Platforms to show: All Mac Windows Linux Cross-Platform

/Mac64bit/Contacts/Contacts History


Required plugins for this example: MBS Mac64bit Plugin, 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: /Mac64bit/Contacts/Contacts History

This example is the version from Mon, 9th Jan 2022.

Project "Contacts History.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() #if Target64Bit and TargetMacOS then if CNContactStoreMBS.available then // ok else MsgBox "please run on OS X 10.11 or newer." quit end if #else MsgBox "Please run with Xojo as 64-bit app on Mac." quit #endif End EventHandler
End Class
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
EventHandler Sub Open() // check authorization m = new MyContactStore dim x as integer = m.authorizationStatusForEntityType(m.CNEntityTypeContacts) Select case x case m.CNAuthorizationStatusAuthorized system.DebugLog "Authorization status: Authorized" QueryHistory case m.CNAuthorizationStatusDenied system.DebugLog "Authorization status: Denied" case m.CNAuthorizationStatusNotDetermined system.DebugLog "Authorization status: Not Determined" m.requestAccessForEntityType m.CNEntityTypeContacts case m.CNAuthorizationStatusRestricted system.DebugLog "Authorization status: Restricted" else system.DebugLog "Authorization status: "+str(x) break end Select End EventHandler
Sub QueryHistory() Dim request As New CNChangeHistoryFetchRequestMBS request.shouldUnifyResults = True request.includeGroupChanges = true request.startingToken = LastTimeToken // nil for all, old token to find new stuff // ask for more keys, so we have data to display dim keys() as CNKeyDescriptorMBS keys.Append CNContactMBS.CNContactOrganizationNameKey keys.Append CNContactMBS.CNContactGivenNameKey keys.Append CNContactMBS.CNContactFamilyNameKey keys.Append CNContactMBS.CNContactTypeKey request.setAdditionalContactKeyDescriptors keys dim error as NSErrorMBS dim result as CNFetchResultMBS = m.enumeratorForChangeHistoryFetchRequest(request, error) if error <> nil then MessageBox error.LocalizedDescription else ShowHistory result LastTimeToken = result.currentHistoryToken end if End Sub
Sub ShowHistory(result as CNFetchResultMBS) dim list as listbox = self.List dim items() as CNChangeHistoryEventMBS = result.ChangeHistoryEvents for each item as Variant in items if item isa CNChangeHistoryAddContactEventMBS then dim his as CNChangeHistoryAddContactEventMBS = item list.AddRow "Add contact "+his.contact.displayName elseif item isa CNChangeHistoryAddGroupEventMBS then dim his as CNChangeHistoryAddGroupEventMBS = item list.AddRow "Add group "+his.group.Name elseif item isa CNChangeHistoryAddSubgroupToGroupEventMBS then dim his as CNChangeHistoryAddSubgroupToGroupEventMBS = item list.AddRow "Add sub group "+his.subgroup.Name+" to "+his.group.Name elseif item isa CNChangeHistoryAddMemberToGroupEventMBS then dim his as CNChangeHistoryAddMemberToGroupEventMBS = item list.AddRow "Add member "+his.member.displayName+" to "+his.group.Name elseif item isa CNChangeHistoryDeleteContactEventMBS then dim his as CNChangeHistoryDeleteContactEventMBS = item list.AddRow "Delete contact "+his.contactIdentifier elseif item isa CNChangeHistoryDeleteGroupEventMBS then dim his as CNChangeHistoryDeleteGroupEventMBS = item list.AddRow "Delete group "+his.groupIdentifier elseif item isa CNChangeHistoryDropEverythingEventMBS then dim his as CNChangeHistoryDropEverythingEventMBS = item list.AddRow "Drop everything." elseif item isa CNChangeHistoryRemoveMemberFromGroupEventMBS then dim his as CNChangeHistoryRemoveMemberFromGroupEventMBS = item list.AddRow "Remove member "+his.member.displayName+" to "+his.group.Name elseif item isa CNChangeHistoryRemoveSubgroupFromGroupEventMBS then dim his as CNChangeHistoryRemoveSubgroupFromGroupEventMBS = item list.AddRow "Remove sub group "+his.subgroup.Name+" to "+his.group.Name elseif item isa CNChangeHistoryUpdateContactEventMBS then dim his as CNChangeHistoryUpdateContactEventMBS = item list.AddRow "Update contact "+his.contact.displayName elseif item isa CNChangeHistoryUpdateGroupEventMBS then dim his as CNChangeHistoryUpdateGroupEventMBS = item list.AddRow "Update group "+his.group.Name else Break end if next End Sub
Property LastTimeToken As MemoryBlock
Property m As MyContactStore
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"
End MenuBar
ExternalFile info
End ExternalFile
Class MyContactStore Inherits CNContactStoreMBS
EventHandler Sub DidChange() System.DebugLog "Contacts Changed" MainWindow.QueryHistory End EventHandler
EventHandler Sub requestAccessForEntityType(granted as boolean, error as NSErrorMBS, tag as Variant) #Pragma unused tag system.DebugLog "requestAccessForEntityType completed" if granted then system.DebugLog "permissions granted" MainWindow.QueryHistory else system.DebugLog "Permissions denied" End If If error <> Nil Then system.DebugLog error.LocalizedDescription end if End EventHandler
End Class
Module UtilModule
Function displayName(extends c as CNContactMBS) As string if c.contactType = CNContactMBS.CNContactTypeOrganization then return c.organizationName else return c.givenName + " " + c.familyName end if End Function
End Module
End Project

See also:

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


The biggest plugin in space...