EKAlarm will not set in iOS 5 - objective-c

I wrote the following snippet to create an event. Setting the alarm works fine in iOS 4, but in iOS 5 it doesn't get set.
Is this a bug or am I missing something?
EKCalendar *cal = [self.eventStore defaultCalendarForNewEvents];
EKEvent *event = [EKEvent eventWithEventStore:self.eventStore];
event.calendar = cal;
// .......
EKAlarm *alarm = [EKAlarm alarmWithRelativeOffset:-3600];
event.alarms = [NSArray arrayWithObject:alarm];
// .......

I had the same error.
The problem seems that startDate shoudln't be the same as endDate... really silly iOS change!

It seems to be related to that's happening in this ticket: EventKit - App freezes when adding an EKEvent with 2 alarms (iOS 5).
If you take a look at the EventKit section in the iOS 5 changes from iOS 4.3 document, it mentions that some items are deprecated for EKEvent. The hierarchy has changed and a new abstract superclass has been added: EKCalendarItem.

Avoid manipulating the alarms array. You need to add the alarm to your event like this:
EKAlarm *reminder = [EKAlarm alarmWithRelativeOffset:-300];
[event addAlarm:reminder];
This will add a reminder 5 minutes before the start time.

Related

How to implement a solution to change the orientation to landscape and vice versa

I'm from RN background and pretty new to Objective-C/Swift. Though it is RN project, but there are lot of implementation written by previous engineers in Objective-C/Swift. This particular implementation was written in Objective-C which is to lock the screen in both portrait and landscape. But the problem here the landscape mode doesn't work for iOS 16.
Upon reading through the docs I discover that iOS 16 uses requestGeometryUpdateWithPreferences which our code need to be updated based on that. I've been looking around for the solution in Objective-C and I found this partial solution and the solution in Swift.
I thought of using the partial solution above with the my little update to define the deviceOrientation. But I know it won't work and is incorrect with the code below. What can I try next?
UIInterfaceOrientation deviceOrientation = [UIApplication sharedApplication].statusBarOrientation;
UIWindowScene *windowScene = ( UIWindowScene *)[[[ UIApplication sharedApplication] connectedScenes] allObjects].firstObject;
UIWindowSceneGeometryPreferencesIOS *perference = [[ UIWindowSceneGeometryPreferencesIOS alloc] init];
perference.interfaceOrientations = 1 < deviceOrientation;
[windowScene requestGeometryUpdateWithPreferences:perference errorHandler: ^( NSError * _Nonnull error) {
NSLog(# "error--%#", error);
}];

UIDatePicker.date bug

I'm having a problem getting the date from UIDatePicker. I know the code of getting the date, but it just keeps on getting the CURRENT date, not the date form the picker.
- (IBAction)buttonPressed:(UIButton *)sender {
NSDateFormatter *formate = [[NSDateFormatter alloc]init];
NSDate *settedDate = self.myPickedDate.date;
[formate setDateFormat: #"dd.MMM.yyyy # HH:mm:ss"];
NSString *dateString = [formate stringFromDate:settedDate];
NSLog(#"datestring: %#", dateString);
}
I set myPicker to 15th May 2015 15:30 and Xcode logs out the current date (if it's 16:19 he will log out 22nd.Apr.2015 16:19, no matter what.
Xcode 5.1.1 on simulator iOS 7.1.2 (haven't tried on real device).
The problem is that in your viewDidLoad you are saying this:
self.myPickedDate = [[UIDatePicker alloc] init];
So, think about that code. What you are doing there is creating a new date picker, completely different from the one in your interface, and substituting it for the one in your interface, to which self.myPickedDate was previously set (because it is an outlet). So from now on, self.myPickedDate refers to a different date picker, one that is not in your interface (it is merely held in memory)! Therefore, nothing you do in the interface, such as setting the date in the date picker you see there, has any effect on self.myPickedDate.
Therefore, to solve the problem, delete that line of code.

Adding historical events to iOS7 calendar

I just ran into an issue that took me a while to solve and hadn't seen it mentioned on SO, so here it is. I was just trying to programmatically add events to my calendar that are over 1 month old and on iOS7 (not iOS6) these events would not show up in a calendar, and neither were they available when I did a (programatic) query of the calendar. Adding events with future dates or dates up to 1 month in the past worked fine.
Here is the code I am using to add the event:
EKEvent *newCalendarEvent = [EKEvent eventWithEventStore:eventStore];
// In seconds; one hour default duration.
#define DURATION_OF_EVENT 60*60
newCalendarEvent.startDate = self.date;
// If I just use the startDate as the end date, then the height of the event in the calendar is really short.
NSDate *endEventDate = [[NSDate alloc] initWithTimeInterval:DURATION_OF_EVENT sinceDate:self.date];
newCalendarEvent.endDate = endEventDate;
newCalendarEvent.title = [self getEventTitle];
newCalendarEvent.calendar = cal;
NSError *error = nil;
[eventStore saveEvent:newCalendarEvent span:EKSpanThisEvent error:&error];
if (error) {
NSLog(#"CalendarIntegration.integrateDate: Error saving event: %#", error);
}
It turns out this seems to be a side effect of iOS7's Setting app setting under Mail, Contacts, Calendars > Synch. My setting was 1 month. By changing it to 3 months, I was able to create events up to 3 months old and have them displayed in the calendar. Note that I am talking about the calendar on the device that created the calendar event, in which case, I can't see how calendar synch would apply. But apparently, not all (e.g., Apple) would agree with this.

How to set badges on app icon when app is in minimize mode?

When application is in minimize state and at the same time notifications come then badges should be see on app icon.
If a notification arrives and your application is not is foreground, the OS handles the notification.
Your notification can have a field badge that will make the OS update the badge. However, this means that the server than sends the notification must have a way of knowing which number should be the badge.
The notification body would look like this:
{
"aps" : {
"badge" : 9
}
}
Heres my solution. I needed to achieve the same thing in an app that I did. I had a queue of Downloads and wanted to use a Badge to show how many downloads were left, and keep updating it even while in the background. Basically my solution was, every time one of the downloads were completed I setup a UILocalNotification with a silent sound, and no message text. Simply just set the badge..As seen below..
- (void)queRequestFinished:(ASIHTTPRequest *)request {
self.inResourceCount -= 1; // Deducted 1 from the total count of downloads in queue.
Class cls = NSClassFromString(#"UILocalNotification");
if (cls != nil) {
UILocalNotification *notif = [[cls alloc] init];
notif.fireDate = [NSDate date]; // Schedule notification for now.
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.soundName = #"silence.caf";
notif.applicationIconBadgeNumber = inResourceCount; // Number you want displayed as Badge.
// This is where the magic happens, and actually changes your badge.
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];
}
}
Id like to point out, that my scenrio may be different from yours. I was using ASIHTTPRequest library, which has support for continuing downloads while backgrounded, and the method above queRequestFinished: is called even while in the background. Hope this helps, if it does mark it as the answer :) .

iOS5 local notification custom sound xcode iOS iPhone objective-c Xcode

I am trying to set custom local notification sound like this:
UILocalNotification *notification = [UILocalNotification new];
notification.timeZone = [NSTimeZone systemTimeZone];
notification.fireDate = date;
notification.alertAction = #"123";
notification.alertBody = #"123";
//!!!
notification.soundName = #"Glass.aiff";
alarmID=[NSString stringWithFormat:#"%i", arrayAlarms.count];
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:alarmID forKey:#"id"];
notification.userInfo = infoDict;
notification.repeatInterval=NSWeekCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
But I hear only default sound. I am testing app on ios5. Great thanks for help in advance and sorry for my english.
Custom Notification sounds are restricted to less than 30 seconds. If your sound is longer than this iOS will play the default sound instead. Could this be your problem?
For more info see here. https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html
"Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead."
Check your syntax , its wrong. check with this,
notification.soundName = "Glass.aiff";
One can still use UILocalNotificationDefaultSoundName for default local notification sound.
notification.soundName = #"Glass.aiff";
That should work. Make sure the sound(Glass.aiff) is actually in your app’s bundle, and is under 30 seconds.We can't set a custom sound that not present in our app's bundle ie from Document folder etc.