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?
-
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?
-
@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)
-
@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 restrictedSeems like module contacts is fully granted, while objc_util is not.
-
@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.
-
-
Alright, thanks.
My fault must be the way I restore the image data. Though my old code used to work.
-
@cvp looking forward to the update😃