Saving an image as Contact Picture, and displaying it while incoming call
Asked Answered
V

2

8

Requirement: I am saving some contacts into the user's iPhone along with a picture (dimensions same as the device). I want this picture to be displayed ON FULLSCREEN whenever the contact calls on that device.

Noticed Example: Truecaller iOS app shows as Red image when the caller is Identified as Spam

Code: This is code I have used to save the contacts data. I am using Contacts.framework

CNMutableContact *newContact = [CNMutableContact new];

newContact.imageData = UIImagePNGRepresentation([UIImage imageNamed:@"blue_bg.png"]);

newContact.contactType = CNContactTypePerson;
newContact.givenName = user.firstName;
newContact.middleName = user.middleName;
newContact.familyName = user.lastName;

NSArray *numbers = [[NSArray alloc] initWithArray:@[[CNLabeledValue labeledValueWithLabel:@"Main" value:[CNPhoneNumber phoneNumberWithStringValue:user.mobileNumber.stringValue]]]];

newContact.phoneNumbers = numbers;

CNContactStore *store = [CNContactStore new];
CNSaveRequest *saveReq = [CNSaveRequest new];

[saveReq addContact:newContact toContainerWithIdentifier:nil];

NSError *error = nil;
[store executeSaveRequest:saveReq error:&error];

if (error) {
    NSLog(@"Contact Save ERROR: %@", error.localizedDescription);
}

Current Scenario: I am getting this image in the iOS Contacts App but its not displayed when that user calls on the iPhone. How does Truecaller do it? What am I missing here?

Volans answered 5/7, 2016 at 17:6 Comment(3)
One of my app i did the same in swift : let contact = CNMutableContact() let image:UIImage = UIImage(imageLiteral: "cat.png") if let imageData:NSData = UIImagePNGRepresentation(image) { contact.imageData = imageData // The profile picture as a NSData object }Apprehensive
@SaRaVaNaNDM: I have done the same thing in ObjC. Were you getting the desired result (full screen caller image)?Volans
Yep i'm getting. I guess its iOS issue, sometimes it won't show the image.Apprehensive
M
0

I think the key issue is the size of the image.If you use a 9:16 image, the problem should be resolved.

Moriahmoriarty answered 27/12, 2023 at 9:59 Comment(0)
M
-1

If the image shows up in the Contacts App it should show up when you're getting called by that person.

Motif answered 13/7, 2016 at 18:32 Comment(5)
It should be happening but it isn't. Only the contact name initials are showing when incoming call. Not sure where I'm going wrong with this simple thing. Do you have some code that is working?Volans
From another website: "It depends from where you selected the picture: only pictures selected from the Camera Roll will be displayed fullscreen." so you probably need to change something in your code to make it work then.Motif
I've read about this before, Will try to workaround this. But then how does Truecaller app do it?Volans
I don't know if it's possible, but it might be they just save that image to your camera roll, set a contact image to the latest image in the camera roll, and then remove the image from the camera roll. (I don't know if this works and if it's possible) but this might be the solution they use.Motif
I dont think this is the case with Truecaller because it never asks for CameraRoll/Photos access permission.Volans

© 2022 - 2024 — McMap. All rights reserved.