• osamu

    Playing around with iOS contacts, I finally got stuck with this ‘notes’ problem and came here. Is it a bug? Ain’t it Apple’s new policy?

    posted in Pythonista read more
  • osamu

    Matching by the name...
    Is this the only way to correlate Pythonista contacts person.id and CNContact identifier()? 😟

    posted in Pythonista read more
  • osamu

    Well, call him up and ask him to write Symphony No.10? 😂

    posted in Pythonista read more
  • osamu

    Thanks ❣️🙏
    Beethoven

    posted in Pythonista read more
  • osamu

    Got it. For loop was no use.

    posted in Pythonista read more
  • osamu

    Wrong: CNSaveRequest.updateContainer_(CNMutableContact)
    Correct: CNSaveRequest.updateContact(CNMutableContact)

    Console:
    First name: Ludwig
    Last name: Beethoven
    Label: passing
    Passing year: 1827
    Passing month: 3
    Passing day: 26

    Final code:

    from objc_util import *
    
    # ObjectiveC contacts
    CNContactStore = ObjCClass('CNContactStore').alloc().init()
    CNContact = ObjCClass('CNContact')
    Containers = CNContactStore.containersMatchingPredicate_error_(None,None)
    for Container in Containers:
        id = Container.identifier()
        predicate = CNContact.predicateForContactsInContainerWithIdentifier_(id)
        # keys not exactly like in Apple doc
        predicate_contacts = CNContactStore.unifiedContactsMatchingPredicate_keysToFetch_error_(predicate, ['familyName', 'givenName', 'middleName', 'dates'], None)
        print('First name: ', end='')
        first_name = input()
        print('Last name: ', end='')
        last_name = input()
        for contact in predicate_contacts:
            if first_name == str(contact.givenName()) and last_name == str(contact.familyName()):
                break
    
    CNMutableContact = contact.mutableCopy()
    dateComponents = ObjCClass('NSDateComponents').alloc().init()
    print('Label: ', end='')
    label = input()
    print(label.capitalize()+' year: ', end='')
    dateComponents.year = int(input())
    print(label.capitalize()+' month: ', end='')
    dateComponents.month = int(input())
    print(label.capitalize()+' day: ', end='')
    dateComponents.day = int(input())
    CNLabeledValue=ObjCClass('CNLabeledValue')
    value=CNLabeledValue.alloc()
    value.initWithLabel_value_(label, dateComponents)
    CNMutableContact.dates=[value]
    CNSaveRequest = ObjCClass('CNSaveRequest').new().autorelease()
    CNSaveRequest.updateContact(CNMutableContact)
    CNContactStore.executeSaveRequest_error_(CNSaveRequest, None)
    

    I couldn’t attach the capture 😣

    posted in Pythonista read more
  • osamu

    Now I’m trying to modify and save ‘dates’ field of an existing contact. Though the following script doesn’t spit errors but nothing happens to the contact. Could anybody help?

    from objc_util import *
    
    # ObjectiveC contacts
    CNContactStore = ObjCClass('CNContactStore').alloc().init()
    CNContact = ObjCClass('CNContact')
    Containers = CNContactStore.containersMatchingPredicate_error_(None,None)
    for Container in Containers:
        id = Container.identifier()
        predicate = CNContact.predicateForContactsInContainerWithIdentifier_(id)
        # keys not exactly like in Apple doc
        predicate_contacts = CNContactStore.unifiedContactsMatchingPredicate_keysToFetch_error_(predicate, ['familyName', 'givenName', 'middleName', 'dates'], None)
        '''
        print('First name: ', end='')
        first_name = input()
        print('Last name: ', end='')
        last_name = input()
        '''
        first_name = 'Ludwig'
        last_name = 'Beethoven'
        for contact in predicate_contacts:
            if first_name == str(contact.givenName()) and last_name == str(contact.familyName()):
                break
        CNMutableContact = contact.mutableCopy()
        dateComponents = ObjCClass('NSDateComponents').alloc().init()
        label = 'passing'
        dateComponents.day = 26
        dateComponents.month = 3
        dateComponents.year = 1827
        '''
        print('Label: ', end='')
        label = input()
        print(label.capitalize()+' year: ', end='')
        dateComponents.year = int(input())
        print(label.capitalize()+' month: ', end='')
        dateComponents.month = int(input())
        print(label.capitalize()+' day: ', end='')
        dateComponents.day = int(input())
        '''
        CNLabeledValue=ObjCClass('CNLabeledValue')
        value=CNLabeledValue.alloc()
        value.initWithLabel_value_(label, dateComponents)
        CNMutableContact.dates=[value]
    
        CNSaveRequest = ObjCClass('CNSaveRequest').new().autorelease()
        CNSaveRequest.updateContainer_(CNMutableContact)
        CNContactStore.executeSaveRequest_error_(CNSaveRequest, None) ```

    posted in Pythonista read more
  • osamu

    @cvp @JonB
    Thank you folks.
    I'm just a Python beginner and I had no place to begin w/ Objective C stuff. Now I think I can begin to try.

    posted in Pythonista read more
  • osamu

    @cvp Sorry, I’d like to know how to assign values to ‘date’ field of contact person.

    posted in Pythonista read more
  • osamu

    @cvp Could you give me an example to assign values?

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!