Get NSURL for image data of contact - ios

I need to get the reference URL for the stored image of a contact.
If I'm getting an image from a UIImagePickerController, I can get that simply by doing this.
NSURL *imageURL = [info objectForKey:UIImagePickerControllerReferenceURL];
But how do I get this NSURL for an image of a contact from the Address Book?
UIImage *contactImage = [UIImage imageWithData:CFBridgingRelease(ABPersonCopyImageData(ref))];
i.e. get the reference URL for contactImage.

The ref argument in your question is not an NSURL, but an ABRecordRef, i.e. the reference to an address book record. You had first to open the address book using code like
CFErrorRef error = nil;
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions (NULL, &error);
and then to find the required person using e.g.
ABRecordRef ref = ABAddressBookGetPersonWithRecordID (addressBookRef,recordID);
This gives you the required ref.

Related

How can I retrieve the metadata of PHAsset?

I am getting the user selected image in PHAsset format. and I want to get the image path.
My goal is to upload the image to Firebase and based their docs, I need to have the image path.
I found from researching that I need to get the metadata of the image first and store it in local file and then I can retrieve the URL. Is it correct?
My question here is (If the above correct), how can I get the metadata of PHAsset image format?
If you want to retrive the image file Path from your PHAsset address then use this function:
[asset requestContentEditingInputWithOptions:[PHContentEditingInputRequestOptions new] completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
NSURL *imageURL = contentEditingInput.fullSizeImageURL;
}];
asset=PHAsset *asset

image uploaded rotated other way

let image_data = UIImageJPEGRepresentation(self.imagetoadd.image!,0.0)
The image in ios, am using swift 3 to do this is being uploaded rotated.How can I solve such thing?
JPEG images usually contain an EXIF dictionary, here are stored a lot information about how the image was taken, image rotation is one of it.
UIImage instances keeps these information (if the original image has it) as well inside a specific property called imageOrientation.
As far as I remember this information is ripped of by using the method UIImageJPEGRepresentation.
To create a correct data instance with the above information you must use Core Graphics methods, or normalize the rotation before sending the image.
To normalize the image something like that should be enough:
CGImageRef cgRef = imageToSave.CGImage;
UIImage * fixImage = [[UIImage alloc] initWithCGImage:cgRef scale:imageToSave.scale orientation:UIImageOrientationUp];
To keep the rotation information:
CFURLRef url = (__bridge_retained CFURLRef)[NSURL fileURLWithPath:path];//Save data path
NSDictionary * metadataDictionary = [self imageMetadataForPath:pathToOriginalImage];
CFMutableDictionaryRef metadataImage = (__bridge_retained CFMutableDictionaryRef) metadata;
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypeJPEG, 1, NULL);
CGImageDestinationAddImage(destination, image, metadataImage);
if (!CGImageDestinationFinalize(destination)) {
DLog(#"Failed to write image to %#", path);
}
Where the -imageMetadataForPath:
- (NSDictionary*) imageMetadataForPath:(NSString*) imagePath{
NSURL *imageURL = [NSURL fileURLWithPath:imagePath];
CGImageSourceRef mySourceRef = CGImageSourceCreateWithURL((__bridge CFURLRef)imageURL, NULL);
NSDictionary * dict = (NSDictionary *) CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(mySourceRef,0,NULL));
CFRelease(mySourceRef);
return dict;
}
This is a copy and paste from a project of mine, you probably need to do a huge refactoring, also because it is using manual memory management in core foundation and you are using SWIFT. Of course by using this last set of instructions, the backend code must be prepared to deal with image orientation too.
If you want to know more about rotation, here is a link.

iOS app: keep old application name as keyword?

I need to rename my application's name.
Is it possible to store some metadata of its old name somewhere?
Users may try to search its old name in the iPhone's search option.
Is there any designated value in the plist file or elsewhere so that its bundle display name is the new name, while the old name is still searchable?
To achieve this your application has to be launched atleast once, and in didFinishLaunchingWithOptions: of your AppDelegate you can index your Core Spotlight searchable item like below:
CSSearchableItemAttributeSet* attributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:#"myApp.image"];
attributeSet.title = #"My Old App";
attributeSet.contentDescription = #"This application help you in acheiving so & so";
CSSearchableItem *item = [[CSSearchableItem alloc] initWithUniqueIdentifier:#"myApp" domainIdentifier:#"com.myapp" attributeSet:attributeSet];
// Index the item.
[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:#[item] completionHandler: ^(NSError * __nullable error) {
NSLog(#"Search item indexed");
}];
You can even add thumbnail image to be shown when the app with old name is searched; You need to add following code before creating the searchableItem
UIImage *image = [UIImage imageNamed:#"MercC"];
NSData *thumbNailData = UIImagePNGRepresentation(image);
attributeSet.thumbnailData = thumbNailData;

How can I get user avatar link of facebook with userid

I have id of user on facebook. Now I want to get user avatar base on the link https://graph.facebook.com on iOS.
Try to use via this link :
https://graph.facebook.com/user_id/picture?type=normal
Hope this works.
As i also gave you the first comment so explaining it.
If you looking the Avatar link try
http://graph.facebook.com/username/picture
where you can try the username like sunnyleone or you can use the facebook userid like for sunnyleone the userid is 131218490419638.
if you looking your facebook id you can get it from here. for your examples.
And One Major thing that nobody checked Image size is small for you can add parameter like
?type=normal
or for more bigger image. But the best one is you can replace the redirect link like.
replace _s to _n
Small Image :
http://profile.ak.fbcdn.net/hprofile-ak-prn1/t5/162024_131218490419638_623017319_s.jpg
Big Image : http://profile.ak.fbcdn.net/hprofile-ak-prn1/t5/162024_131218490419638_623017319_n.jpg
then you can get the bigger Image.
Hope this will help you
use #"https://graph.facebook.com/uid/picture" to get facebook profile picture
NSString *urlStr = [NSString stringWithFormat:#"http://graph.facebook.com/%#/picture?type=large", userId];
NSURL *url = [NSURL URLWithString:urlStr];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];

Random URL website address from core data that holds a picture to display in UIImage in iOS?

I'm new to using xcode, so any information or links would be helpful. If I had a RANDOM website url in coredata, how would I be able to direct my UIImage to get the photo from that website to display in iOS?
Let's say imageURL is a NSString * ivar or property where you hold your URL.
To get the image this should work:
NSURL *url = [NSURL URLWithString:imageURL];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *myImage = [UIImage imageWithData: imageData];
Of course you should add some error checking but this should get you into the right direction.

Resources