I have the following code :
EKEventEditViewController *addController = [[EKEventEditViewController alloc] initWithNibName:nil bundle:nil];
EKEvent * event = [EKEvent eventWithEventStore:eventStore];
event.startDate = startDate;
event.endDate = endDate;
addController.eventStore = self.eventStore;
addController.event = event;
addController.editViewDelegate = self;
[self presentModalViewController:addController animated:YES];
[addController release];
It show me a screen to add event like iCal, but when I press "done" button to add event I got an alert "That event does not belong to that event store." and in console log I got "Calendar: unable to save: Error Domain=EKErrorDomain Code=11 "That event does not belong to that event store." UserInfo=0xfecb150 {NSLocalizedDescription=That event does not belong to that event store.}" , but this just occur in iOS 5., ok with 4. Can anyone help me this :)
I get the same behaviour as described by #Airsource Ltd in his answer:
... If I try and save an event which has starttime == endtime, then I initally get an error "No end date has been set". If I then set a different end time, I get "That event does not belong to that event store".
However, this only seems to happen if the event's initial values for startDate and endDate are exactly equal.
This seems to be an iOS 5 bug. My workaround: make the event's initial startDate and endDate always differ just a bit, e.g. a second:
if ([event.endDate isEqualToDate:event.startDate]) {
event.endDate = [event.startDate dateByAddingTimeInterval:1.0]; // add one second
}
I have pretty much the same problem. If I try and save an event which has starttime = endtime, then I initally get an error "No end date has been set". If I then set a different end time, I get "That event does not belong to that event store".
I noted in the debugger that normally when you cancel the event details are still present in EKEventEditController.event. However, if you cancel following the "No end date has been set" error, the event only contains a start and end time. The title has been wiped. My theory is that the reference to the eventStore has also been nilled out, which is what triggers the second error.
I interrupted the code following hitting OK on the "No end date error' but before hitting cancel and inspected the controller's event - but all looked ok, which means my theory can't be quite right. However there must be some disconnect appearing between the eventstore and the event for this error to appear.
I also get this problem only on iOS 5. My iOS 4.2 device is fine.
Related
I just took a stab at creating some code (pasted below) that would check for a day change. However, now I'm reading that there's a special function for day changes.
NSCalendarDayChangedNotification
Apparently it works in iOS8 and later. But people keep using the phrase "you can listen to it"... as if using that function is like tuning into a radio station. I looked it up and the last WWDC provided a presentation with some relevant code:
Reacting to the Change of Day • You may want to run some code when the
day changes NSCalendarDayChangedNotification • Example
noteCenter = [NSNotificationCenter defaultCenter];
observer = [noteCenter addObserverForName:NSCalendarDayChangedNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
// your code here
}];
My Question
The PDF I found doesn't say much else though. So my question is how does this function work? The PDF makes it seem like it truly is just this simple, paste that code in and I'm done. Is that true? Will it adjust for timezones? Do I have to enable this notification center that it is referencing?
My code (not sure if it would work):
//Find out if it's a new day
let lastDateUsed_NSDefault = NSUserDefaults.standardUserDefaults()
if let endOf_LastDateUsed = lastDateUsed_NSDefault.objectForKey("lastDateUsed") as! NSDate! {
print("Success! NSUserDefault key: 'lastDateUsed' returned \(endOf_LastDateUsed)")
//Check if the day has changed
let calendar = NSCalendar.currentCalendar()
let startOfToday = calendar.startOfDayForDate(now)
if endOf_LastDateUsed.compare(startOfToday) == NSComparisonResult.OrderedAscending {
//endOf_LastDateUsed is greater than startOfToday.
print("Do nothing! Last date used must have been today!")
} else if endOf_LastDateUsed.compare(startOfToday) == NSComparisonResult.OrderedAscending {
//Day has changed. Run alert.
//Save "endOfToday" date value to NSDefault
let endOfToday = startOfToday.dateByAddingTimeInterval(24 * 60 * 60)
NSUserDefaults.standardUserDefaults().setObject(endOfToday, forKey:"lastDateUsed")
print("Time stored in NSDefault: \(endOfToday)")
}
}
else {
print("Failure! NSUserDefault key: 'lasteDateUsed' returned nothing. No record.")
//First time user - Set end of today
let calendar = NSCalendar.currentCalendar()
let startOfToday = calendar.startOfDayForDate(now)
print("startOfToday: \(startOfToday)")
let endOfToday = startOfToday.dateByAddingTimeInterval(24 * 60 * 60)
//Store
NSUserDefaults.standardUserDefaults().setObject(endOfToday, forKey:"lastDateUsed")
print("Time stored in NSDefault: \(endOfToday)")
}
The documentation (which was slightly harder to locate than I'd have hoped, admittedly) is reasonably clear:
Posted whenever the calendar day of the system changes, as determined by the system calendar, locale, and time zone.
So yes, it should handle daylight saving changes appropriately, given that it knows about the time zone. I don't know about enabling the notification centre, but that should be easy enough to test by adjusting the system clock or time zone on a device and seeing what happens.
(What isn't clear from the docs is whether this event is fired if the date is changed via manual intervention, e.g. through changing the system time or time zone in a way that directly changes the date. It would be worth you experimenting with that.)
In our Maximo workflow we have a few schemas in which work order reaches a Condition node with a check on a startdate. If current date is less than it's startdate then work order goes to a Wait node with "maximo.workorder.update" condition. So when the scheduled date for WO comes people need to go to WO tracking and save this WO manually. Only then it continues it's way through the workflow. Otherwise WO will sit on that Wait node till the end of time.
What I want to do is to trigger this update event by crontask everyday so when the right date comes WO will wake up by itself.
I inspected source code for a Save button in WO tracking application and found that no matter what there's MboRemoteSet.save() method call. I assumed that you need to get some changes done and then call save() on the right MboSet. Also I know that in DB there's table called EVENTRESPONSE that keeps track of WOs sitting on the Wait nodes in workflow.
My crontask class contains this code:
MXServer mxServer = MXServer.getMXServer();
UserInfo userInfo = mxServer.getUserInfo("maxadmin");
woSet = mxServer.getMboSet("WORKORDER", userInfo);
...
String query = "select sourceid as WORKORDERID from EVENTRESPONSE"
+ " where eventname = 'maximo.workorder.update'"
+ " and sourcetable = 'WORKORDER'";
SqlFormat sqf = new SqlFormat("workorderid IN (" + query + ")");
woSet.setWhere(sqf.format());
MboRemote wo;
Date currentDate = new Date();
for (int i = 0; (wo = woSet.getMbo(i)) != null; i++) {
System.err.println(wo.getString("description"));
wo.setValue("CHANGEDATE", currentDate);
}
woSet.save();
workorder.changedate successfully refreshes but "maximo.workorder.update" event doesn't proc and WO stays on the Wait node.
So, how should I fire maximo.workorder.update?
This response comes a year late, I understand, but it may help others.
It is possible to use an "Escalation" to identify all work orders that have had their time to come and use an action on the escalation to update something on the work order. This will result in Maximo saving the change, thereby triggering the wait node of the workflow, all without any code, just configurations.
I have done something similar in the past and usually I end up flipping a YORN field that I had created for this purpose.
I am working on a game in Cocos2d for iPhone.
In my init method I have an object (type id) declared as follows (also note bossDir is declared as 1):
bossMov = [CCMoveTo actionWithDuration:1.0f position:ccp(75*bossDir, 320-55)];
[boss runAction:bossMov];
Then in a timer method I have:
if ([bossMov isDone] == YES) {
bossDir = -bossDir;
[boss stopAllActions];
[boss runAction:bossMov];
}
It moves the boss once, but after that it gives EXC_BAD_ACCESS and points me to a line in the file "CCTimer.m" that says:
if( elapsed >= interval ) {
impMethod(target, selector, elapsed); //This line in particular.
elapsed = 0;
}
How can I fix this problem?
have you tried the NSZombieEnabled because i am not a cocos2d guy but just as a suggestion i am telling you this. Because bad access error comes only when you are pointing to an object which is no longer in the memory and the application crashes if you try to do so
You are not retaining bossMov action. So when you call [boss stopAllActions]; it is released and deallocated. Then you are trying to run the deallocated action - so you get the bad access.
I am using core motion on my app. I have the motionManager object assigned to a property on my main class. Something like
#property (nonatomic, retain) CMMotionManager *motionManager;
every time I will use core motion, I assign it using something like:
- (void) initializeCoreMotion {
CMMotionManager *myMotionManager = [[CMMotionManager alloc] init];
self.motionManager = myMotionManager;
[myMotionManager release];
}
Then, on the method that samples that data, I have this to read the timestamp of a sample.
CMDeviceMotion *motion = self.motionManager.deviceMotion;
timestamp = motion.timestamp;
if (firstTime) {
timestampReference = timestamp;
firstTime = NO;
} else {
timestamp = timestamp - timestampReference;
}
That is: the first time it samples, it stores the initial value. The subsequent times it samples, it will subtract the current value from the reference to know how many seconds passed.
the problem is this. Suppose I am sampling one time per second. I first sample for 10 seconds. So timestamp variable will go like 0, 1, 2, 3, 4, 5...10. Then I stop and do not sample for 20 seconds. When I start sampling again. The second time, timestamp will start at 31, 32, 33, 34...
I have checked the sampling method and firstTime is YES every time a first sample occurs...
any thoughts? How do I reset that?
thanks.
Seems to be fine the way you do it. But why do you create a new instance of CMMotionManager? I use:
if ([motionManager isDeviceMotionAvailable] && [motionManager isDeviceMotionActive]) {
[motionManager stopDeviceMotionUpdates];
}
and to continue:
[motionManager startDeviceMotionUpdatesToQueue:operationQueue withHandler:deviceMotionHandler];
I was curious to see if there is still something wrong in iOS with the timestamps and thus I just tried out your code or similar thing using a static. Everything works as expected. Maybe your timestampReference is overwritten somewhere else?
I have been trying to use UILocalNotification and setting timezone to some other timezone than my default.
The purpose is to do something like:
-User will schedule an alert with time and timezone
-Show alert when that timezone becomes specified time.
In more verbal description, let say I live in LosAngeles and my gf is in Chicago. I want to set up an alert when chicago is 7am, for weekdays.
For one alert, I can do without timezone, to do absolute time. But I want to allow users to set repeat flags, in which case I can't seem to do - I tried setting localnotification's timezone property to chicago as above example, however the local notification will not fire.
I logged the uinocalnotification during serialization process, and here's one output:
"<UIConcreteLocalNotification: 0xfb25a50>{fire date = 2011-02-06 06:02:00 -0800, time zone = America/Chicago (CST) offset -21600, repeat interval = 16, next fire date = 2011-02-06 08:02:00 -0800}"
I set firedate for 9:02am chicago absolute time, and timezone to cst - and the log does mention that the fire date is indeed 06:02 my local time. However, nothing happens. Also, next fire date is weird since it should be +1 day, not +2 hrs.
Here's how I set this up:
Class classUILocalNotification = NSClassFromString(#"UILocalNotification");
if (classUILocalNotification != nil) {
id note = [[classUILocalNotification alloc] init];
NSString *body = #"body message";
switch (repeatflag) {
case 1: [note setRepeatInterval:NSDayCalendarUnit]; break;
case 2: [note setRepeatInterval:NSWeekdayCalendarUnit]; break;
case 3: [note setRepeatInterval:NSWeekCalendarUnit]; break;
case 4: [note setRepeatInterval:NSMonthCalendarUnit]; break;
case 5: [note setRepeatInterval:NSYearCalendarUnit]; break;
default: break;
}
[note setFireDate:dt];
[note setAlertBody:body];
[note setTimeZone:timezone];
[note setHasAction:NO];
}
This seems like some unknown behavior. Anyone have a better way to achieve what I am trying to do?
Thanks!
There appears to be a bug with UILocalNotification when using non-local timezone. The first event fired is fired for the correct date and time and timezone. However, subsequent events fire for the given date and time in your local timezone instead of the one set in the setTimeZone method. [iOS 6.1]