iOS Accessing dates from images in the bundle - ios

My app is an image loader that copies images from the bundle to the camera roll. Unfortunately the only date I can get from the images is NOW. I have tried copying the images to my app as well as using references. Both result in the same date which is NOW.
Currently I am using:
NSMutableDictionary *EXIFDictionary = [[metadataAsMutable objectForKey:(NSString *)kCGImagePropertyExifDictionary]mutableCopy];
[EXIFDictionary setObject:[NSDate date] forKey:(NSString*)kCGImagePropertyExifDateTimeOriginal];
NSLog(#"Date %#", [EXIFDictionary valueForKey:(NSString*)kCGImagePropertyExifDateTimeOriginal]);
Is there any way to get the actual asset creation date from an asset in the bundle?
Thanks in advance,
Joe

Related

Can I upload an MP3 file to my server from iOS?

I was googling this question but nothing useful or current came up. I'd like to know if (and if, how) you can select an MP3 file (from itunes?) and upload the contents to one of my own servers on iOS (iphone & ipad app).
One of my clients is asking me if it's possible to do this, and I havn't found the answer yet.
Thanks in advance!
The short answer would be YES.
Here is a working solution for me. But you need to use a third party library. Then this is what you need to do:
Create a temp folder either in the NSDocuments directory or a temp directory.
Use MPMediaQuery to load the music files.
The object that you will get from the MPMediaQuery is an MPMediaItem. With this you can get the asset URL of the media item.
Code:
NSString *assetURL = [mediaItem valueForProperty:MPMediaItemPropertyAssetURL];
get the extension of with the asset URL
NSString *extension = [TSLibraryImport extensionForAssetURL:assetURL];
set a location URL (This will be the location where the mp3 music data will be imported).
NSString *locationURL = [[NSURL fileURLWithPath:[path stringByAppendingPathComponent:musicTitleYouWant]] URLByAppendingPathExtension:extension];
Now you can import the contents of the mp3 from to the directory you set earlier.
TSLibraryImport *libraryImport = [[TSLibraryImport alloc] init];
[libraryImport importAsset:assetURL toURL:locationURL completionBlock:^(TSLibraryImport *libraryImport)
{
if(libraryImport.status == AVAssetExportSessionStatusCompleted)
{
//Once complete the file will be store on the location URL you set earlier. Now you can get the file from that location and convert it to NSData and send it to the server. There are plenty of ways to do that.
}
else
{
//Here means import failed. :(
}
}];
Hope this helps. :)

iOS/Xcode: Select all images from camera roll between user-set dates

I'm trying to build a simple iOS application where a user sets some dates, and the application then fetches all the images that were taken between those two dates.
I've just started, but currently have the view to select the two dates and successfully log them to the console.
The part I need help with is requesting access to the photos and fetching the photos between the dates.
Any help is much appreciated!
- (IBAction)submitDates {
NSDate *dateFromPicker = [_fromDate date];
NSDate *endDateFromPicker = [_endDate date];
NSLog(#"From date: %# and end date: %#", dateFromPicker, endDateFromPicker);
//Request images between dates using ALAssetPropertyDate
}

Content modification date of an file in Cocoa

How can I find out when a file was last time modified in Cocoa?
I tried using NSFileModificationDate attribute of an NSFile but the modification date gets update when you read a file. I just want to know when it was last time changed like in the Mac OS X Finder.
You can try next code:
NSDate *fileModificationDate = nil;
[fileUrl getResourceValue:&fileModificationDate forKey:NSURLContentModificationDateKey error:nil];
NSLog(#"modification date %#", fileModificationDate)
You can see the resource keys in NSURL.h - NSURLContentModificationDateKey and other.
Hope it will help.

Comparing creation/modification date of NSData objects

At first I have a plist file in app bundle. At some point the file can get updated (downloaded into Documents Folder). Whats the best way to know which file is newer? The mainbundle plist could get updated with new App Version and then the downloaded one would be the oldest.
I do have a timestamp inside the plist but I actually don't want to load each of them into memory to be able to compare the dates, as each takes 1-2 seconds.
Is there some kind of creation date that I could compare?
How about this:
NSError *error = nil;
NSDictionary* dict = [NSFileManager attributesOfItemAtPath:path error:&error];
NSDate* date = [dict fileModificationDate];
You can use -[NSFileManager attributesOfItemAtPath:error:] to get the filesystem-level attributes of each plist, then compare values for modification dates (using the NSFileModificationDate string constant).

Image download from AWS S3 taking too long using the AWSiOSSDK.framework

It's taking ~7.5 seconds to download a 700 KB image file from AWS S3.
I wrote this method to download an image from AWS S3:
+ (UIImage *)downloadImageFromPath:(NSString *)path
{
NSDate *methodStart = [NSDate date];
S3GetObjectRequest *getObjectRequest = [[S3GetObjectRequest alloc] initWithKey:path withBucket:AWS_BUCKET];
AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY];
S3GetObjectResponse *response;
#try
{
response = [s3 getObject:getObjectRequest];
}
#catch(NSException* ex)
{
return [UIImage imageNamed:#"blank.jpg"];
}
NSData *data = response.body;
UIImage *image = [UIImage imageWithData:data];
NSDate *methodFinish = [NSDate date];
NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:methodStart];
NSLog(#"executionTime = %f", executionTime);
return image;
}
I just added code at the beginning and end to time the method.
As I mentioned above, it's taking ~7.5 seconds to complete.
I'm running it in the background with GCD with priority DISPATCH_QUEUE_PRIORITY_HIGH, and there's nothing else in the queue when it runs.
Anyone know why it's taking so long? Would be happy to provide more info.
This is a known problem, S3 alone is slow when it comes to the upload and download of images.
Well, it actually isn't a problem when you enable CloudFront and use other AWS services.
What you are looking for is the Cloudfront CDN from Amazon. You can specify an origin (that would be your S3 bucket in your case) and then your files will be distributed to all the Amazon Cloudfront edge locations worldwide. Check out their FAQ and the list of edge locations.
You would upload to a central server, where majority of your users would be (estimation). And download from a signed URL in which directs you to a server closest to the user that contains a copy of your bucket... You can also cache the images on the servers to make uploading and downloading faster.
Also, I am not sure how you determine path (the key), but if you are listing keys from S3 buckets, stop that! Its slow! You should use DynamoDB or SimpleDB, both alternatives to storing small datasets, DynamoDB is super fast but doesn't really have query options, you can store all keys into DynamoDB with a certain format and match them.
You could use SimpleDB and store all your keys with relevant attributes (properties) and query SimpleDB using SELECT expressions similar to SQL -- but a slightly different syntax
There are a lot of things you can do to optimize S3!
If you need detailed steps on everything to do, I will do it if you put a bounty on the question. Its not easy picking this up from the documentation but could take me hours to write as well, and I have school!
After following all these steps, I reduced ~8 seconds to almost the snap of a thumb!

Resources