1

I'm setting a UILocalNotification to notify the user about an event.

My problem is the simulator crashes with the message "Thread 1:signal SIGKILL", after setting the notification and closing the app.

I know about this answer, but I'm not storing anything in the userinfo dictionary.

Here's the code:

NSDate *alertTime = [[NSDate date]
                     dateByAddingTimeInterval:10];
UIApplication* app = [UIApplication sharedApplication];
UILocalNotification* notifyAlarm = [[UILocalNotification alloc] init];

if (notifyAlarm)
{
    notifyAlarm.fireDate = alertTime;
    notifyAlarm.timeZone = [NSTimeZone defaultTimeZone];
    notifyAlarm.repeatInterval = 0;
    notifyAlarm.alertBody = @"Testing notification.";
    [app scheduleLocalNotification:notifyAlarm];
    NSLog(@"Notification set");
}

Do you have any idea why this could happen?

Thanks

Community
  • 1
  • 1
JakesRassie
  • 616
  • 1
  • 6
  • 20
  • 1
    Can you post the related method or code ? – Midhun MP Jul 15 '13 at 12:08
  • I have updated my question for you. – JakesRassie Jul 15 '13 at 12:11
  • Paste the code where you receivde the notification – Antonio MG Jul 15 '13 at 12:16
  • That is the only code I have, I don't have any other code for receiving the notification. – JakesRassie Jul 15 '13 at 12:22
  • @JakesRassie: I Checked your code, It's not crashing for me. So possibly there is any issue with notification receive or another code – Midhun MP Jul 15 '13 at 12:52
  • Thanks, note that the application crashes when I set a notification and completely close it (not suspended). And I do not implement a notification receive anywhere, can how please show me hoe to implement this? – JakesRassie Jul 15 '13 at 13:01
  • @JakesRassie: How did you close the app ? Are you using the Stop button of xcode or any other way ? – Midhun MP Jul 16 '13 at 04:12
  • No, I set the notification in the app and then suspend it by pressing the middle button on the iPhone, then I close it by double tapping the button and hold my finger on the application until the close (-) option appears on the application icon. – JakesRassie Jul 16 '13 at 05:29

1 Answers1

1

I experienced the same issue, and after some experimentation learned enough to be able to work around it.

First, note that you can trigger this crash/hang at will simply by following these steps:

  1. Launch your app from Xcode (on either a device or a simulator).
  2. Optionally trigger a notification, and then press the Home button to minimise your app, and then double-tap the home button and fully close your app from the dock that appears.
  3. Without unplugging the device, closing the simulator, or closing Xcode, relaunch your app directly from the device or simulator, either by tapping a notification that summons the app or simply by tapping the app's icon on the home screen.

Now, if you're on a simulator, the app will immediately crash, and if you're on a real device, the entire device will hang and become unresponsive even to pressing the Home button until you unplug it or press the Run button again in Xcode.

The issue seems to manifest itself both in Xcode 4.6.3 and Xcode 5.0; I haven't tried other versions.

Needless to say, this bug really sucks if you're trying to test user interaction paths that involve fully relaunching the app from a notification, like the question asker here is (rather than simply testing the case where notifications bring your app into the foreground from the background). Fortunately, the bug is reasonably easy to work around.

If you're on a device, the workaround is simply: unplug the device from your Mac. The bug described above only manifests itself if the device is plugged into Xcode when you try to launch the app.

If you only have access to the simulator, it's a little trickier, but only slightly. First, use the instructions here to enable you to launch the simulator from outside Xcode:

  1. In Finder, browse to /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/
  2. Drag the iOS Simulator app from that folder to your dock.
  3. You can now launch the simulator as a standalone app from your dock any time you want to.

Now to test apps that use local notifications to completely relaunch the app:

  1. Launch your app on the simulator from Xcode.
  2. Trigger your local notification.
  3. Exit your app with the Home button.
  4. Double tap the home button and close your app from the simulator dock.
  5. Close the simulator with command + q
  6. Relaunch the simulator from the dock of your Mac.
  7. Wait for your notification.
  8. Tap the notification to relaunch the app.
  9. Observe that it doesn't instantly crash! Yay!

It's pretty silly that this is necessary, but at least applying this workaround doesn't take long.

Community
  • 1
  • 1
Mark Amery
  • 143,130
  • 81
  • 406
  • 459