def main():
	store = CNContactStore.alloc().init().autorelease()
	# Find the first contact that matches the name.
	pred = CNContact.predicateForContactsMatchingName_(CONTACT_NAME)
	fetch_keys = ['imageDataAvailable', 'imageData']
	people = store.unifiedContactsMatchingPredicate_keysToFetch_error_(pred, fetch_keys, None)
	if not people:
		print('No person found with the name "%s"' % (CONTACT_NAME,))
		return
	p = people[0]
	has_image = p.imageDataAvailable()
	if has_image:
		# Show the existing picture of the contact:
		img_data = p.imageData()
		img_data_str = string_at(img_data.bytes(), img_data.length())
		img = ui.Image.from_data(img_data_str)
		img.show()
	# Pick a new image from photos:
	new_img_data = photos.pick_image(raw_data=True)
	if new_img_data:
		# Note: objc_util automatically converts bytearray to NSData
		new_img_bytes = bytearray(new_img_data)
		# Create a mutable copy of the fetched contact...
		mutable_contact = p.mutableCopy().autorelease()
		# Assign new image data...
		mutable_contact.imageData = new_img_bytes
		contacts.save()
		# Create a save request for he contact, and execute it...
		save_req = CNSaveRequest.new().autorelease()
		save_req.updateContact_(mutable_contact)
		store.executeSaveRequest_error_(save_req, None)
def write_contact(newChapters, name='Novels'):
	"""update records of the last chapter you saw
	newChapters: list of str: the last chapter you saw
	name: str: a name in the Contacts
	"""
	person = contacts.find(name)[0]
	# 读取各小说标签
	catalog = [novel[0] for novel in person.phone]
	# 在 phone 属性写入各小说标签和相应的已阅章节数
	person.phone = [(n, c) for n, c in zip(catalog, newChapters)]
	contacts.save()
示例#3
0
# https://forum.omz-software.com/topic/2496/add-email-to-contacts/2

import contacts
people = contacts.get_all_people()
print(people[0].full_name)

emails = people[0].email
emails.append(('$!<Other>!$', '*****@*****.**'))
people[0].email = emails

contacts.save()

# coding: utf-8

# https://forum.omz-software.com/topic/2496/add-email-to-contacts

import contacts

people = contacts.get_all_people()
print people[0].full_name

emails = people[0].email
emails.append((u'$!<Other>!$', u'*****@*****.**'))
people[0].email = emails # !!!

contacts.save()