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

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
}

Related

How to get UTC universal time from CLLocation locations?

It looks like the timestamp property of CLLocation takes the device's current date and time... I have this code snippet:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *newLocation = [locations lastObject];
NSDate *eventDate = newLocation.timestamp;
long long locTimestamp = [date timeIntervalSince1970] * 1000;
NSLog(#"Loc timestamp: %lld:", locTimestamp);
}
At the moment I'm writing this, if I print the description of eventDate in the Xcode's debug area console, I get:
Printing description of eventDate:
2015-08-26 15:14:09 +0000
And if I change the date in the device's settings, I get that wrong date in evenDate:
Printing description of eventDate:
2015-07-25 15:16:33 +0000
Maybe I'm misunderstanding the NSDate that is returned in the timestamp property... it really takes the date and time you have set in the device, or it is just given the format of those device's settings?
The point is, I need to get UTC times of locations to report them to a server and make some comparisons between different devices, and if user changes the date and time settings of his device and my app sends wrong or "fake" timestamps, my app couldn't perform well...
It seems that it is possible in Android apps to get the NMEA data from GPS and then get the universal time of positions, but I canĀ“t find that in iOS. Is it possible to get it in iOS?
I need help with this issue, thanks in advance
You can convert the timestamps into any calendar or timezone you want via the NSCalendar and NSDateFormatter and NSLocaleclasses. Docs here

create a custom calendar

I want to create a new custom calendar on iOS, in my application.
I search for some explications on how do it work. But my code doesn't work / the calendar is not created
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKSource *theSource = nil;
for (EKSource *source in eventStore.sources) {
if (source.sourceType == EKSourceTypeLocal) {
theSource = source;
break;
}
}
NSString *identifier;
EKCalendar *cal;
if (identifier == nil)
{
cal = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:eventStore];
cal.title = #"MyCustomCalendar";
cal.source = theSource;
[eventStore saveCalendar:cal commit:YES error:nil];
NSLog(#"cal id = %#", cal.calendarIdentifier);
}
else
{
cal = [eventStore calendarWithIdentifier:identifier];
}
I'm not sure if you are completely set on using EKCalendar, but you do not need to to make a calendar in iOS. You can design your own however you want with a UICollectionView or Buttons laid out dynamically. The important part is to make sure all of your dates are arranged correctly, which is not necessarily trivial. But, if you have a good way to get the first weekday for the first day of a given month, you can get it done. I followed this algorithm: http://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week which seemed a bit complicated, but in practice was easy to code and reliable. Otherwise I believe apple has a 'firstWeekday' method/property you can try, but that didn't work for me. Once you have the right first weekday you can enumerate through the days of the rest of the month and put them how you want on your calendar.
It seems like you are unsure how to setup your calendar data with EKCalendar. I found a nice tutorial you may find useful:
http://oleb.net/blog/2012/05/creating-and-deleting-calendars-in-ios/
For more specific questions try the documentation, you can find it with a google search.
Otherwise, what kind of data export are you looking for? iCloud? Local? Are you working with an actual calendar provided or just saving something with all of your calendar data that another application can read?
The one possible way to get this issue is, mismatching calendar source type.
Since you've created the calendar with local source type, system could not find local source if you already synced your iCloud / gmail / exchange calendars.
So my suggestion is don't stick with local source and try to create the calendar in any available source. If you go for this approach, you'll also be ready for solving appropriate issues (like the case iCloud is synced but user has not given permission for iCloud-calendar sync).

iOS Accessing dates from images in the bundle

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

DatePicker not returning selected date iOS

I am trying to get the selected date from a DatePicker and all I get is the current system date. Any ideas why?
I am doing it through the simulator as I do not have a device. Here is the code I use to get the date.
[self scheduleLocalNotification:timerPicker.date];
I have also used this to see if it works:
NSDate *d = [timerPicker date];
[self scheduleLocalNotification:d];
After several reboots of XCode and no code changes it magically started working.

Time picker shows wrong time iphone sdk

I have time picker in my app. I'm showing timePicker.date and the time is wrong.
NSLog is
NSLog (#"date : %#",[timePicker.date description]);
log is like date: 2012-02-07 17:00:01 +0000
i think that problem is in timezone
in ViewDidLoad i have this code
timePicker.locale = [NSLocale currentLocale];
timePicker.timeZone = [NSTimeZone localTimeZone];
but it isn't working...
Can somebody help me to solve my problem. Thanks
It is likely that the time picker is correctly applying time zone, but you're logging it using GMT rather than local time so that it just looks wrong. If you want to display the time returned from your time picker using local time, use NSDate's descriptionWithCalendarFormat:timeZone:locale: method, or use the NSDateFormatter class to get complete control over how your date is displayed.

Resources