omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Has CNContactImageData been changed?

    Pythonista
    2
    7
    72
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • osamu
      osamu last edited by osamu

      I have developed the library compatible w/ contacts, and yet handle Google contacts at the same time, importing obj_util library.
      After upgrading iOS to 16.4.1, contact.image_data of my library returns funny string as follows;
      {length = 4107, bytes = 0xffd8ffe0 00104a46 4946001 0100001 ... cd7d516a 86cfffd9 }

      This is the data as it is, " ... " is NOT my abbreviation.

      Standard contacts library works just fine.

      Does anybody know if there has been any change to iOS? Was image data banned just like note was?

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @osamu last edited by cvp

        @osamu I use Pythonista contacts module and Person.image_data still works like before.
        I have an IPad Air 5 under iPadOS 16.4.1.

        I did not try to print image_data but I use it to create an ui.Image via

        img = ui.Image.from_data(person.image_data)
        
        osamu 1 Reply Last reply Reply Quote 0
        • osamu
          osamu @cvp last edited by

          @cvp Here’s my test script. I’m curious to how it runs on other iOS versions. Pythonista 3 doesn’t run anymore on my iPad Air 1.

          —-script
          from contacts import *
          from objc_util import *

          entityType = 0 # case contacts
          status = ('notDetermined', 'restricted', 'denied', 'authorized')

          def request_access():
          CNContactStore = ObjCClass('CNContactStore').alloc().init()
          return int(str(CNContactStore.requestAccessForEntityType
          (entityType).result_(None)))

          result = "authorized" if is_authorized() else "denied"
          print(f"Module contacts is {result}")

          result = status[_request_access()]
          print(f"Module objc_util is {result}")

          —-result on my iPhone XR
          Module contacts is authorized
          Module objc_util is restricted

          Seems like module contacts is fully granted, while objc_util is not.

          cvp 2 Replies Last reply Reply Quote 0
          • cvp
            cvp @osamu last edited by cvp

            @osamu I don't understand why you need to call requestAccessForEntityType.

            I can access contacts with objective C without calling this method.

            This works

            from objc_util import *
            import contacts
            import ui
            
            # ObjectiveC contacts
            objc_contacts = {}
            CNContactStore = ObjCClass('CNContactStore').alloc().init()
            #print(dir(CNContactStore))
            CNContact = ObjCClass('CNContact')
            Containers = CNContactStore.containersMatchingPredicate_error_(None,None)
            containers = {}
            for Container in Containers:
                id = Container.identifier()
                containers[id] = Container
                #print(dir(Container))
                predicate = CNContact.predicateForContactsInContainerWithIdentifier_(id)
                # keys not exactly like in Apple doc
                # found a sample here https://github.com/tdamdouni/Pythonista/blob/master/contacts/Add%20Twitter%20Profile%20Picture%20to%20iOS%20Contacts.py
            
                predicate_contacts = CNContactStore.unifiedContactsMatchingPredicate_keysToFetch_error_(predicate, ['familyName','givenName','middleName', 'imageData', 'imageDataAvailable'], None)
                for contact in predicate_contacts:
                    # crash if attribute not in fetched contacts
                    name = str(contact.givenName()) + '|' + str(contact.middleName()) + '|' + str(contact.familyName())
                    cont_per_name = objc_contacts.setdefault(name, [])
                    cont_per_name.append(id)
                    if contact.imageDataAvailable():
                      print(contact.imageData())
                      UIImage_data = nsdata_to_bytes(ObjCInstance(contact.imageData()))
                      ui_image = ui.Image.from_data(UIImage_data)
                      ui_image.show() 	
                      break
            

            You said

            After upgrading iOS to 16.4.1, contact.image_data of my library returns funny string as follows;
            {length = 4107, bytes = 0xffd8ffe0 00104a46 4946001 0100001 ... cd7d516a 86cfffd9 }

            It is normal, I think, the ... are only there to show it is a long field.

            1 Reply Last reply Reply Quote 0
            • cvp
              cvp @osamu last edited by

              @osamu said

              Pythonista 3 doesn’t run anymore on my iPad Air 1.

              Pythonista 3.4 does not run under iOS 12 but @omz should provide an update, as he said in twitter

              alt text

              osamu 1 Reply Last reply Reply Quote 0
              • osamu
                osamu last edited by

                Alright, thanks.

                My fault must be the way I restore the image data. Though my old code used to work.

                1 Reply Last reply Reply Quote 0
                • osamu
                  osamu @cvp last edited by

                  @cvp looking forward to the update😃

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors