1

I am getting constant and seemingly random crashes in my NotificationService app extension. This is my first app extension so I'm not sure how debugging normally works, but my exceptions breakpoint is not getting triggered. The extension just exits and the default notification goes through. I've been able to track down specific spots where the extension crashes using line breakpoints and simply stepping through until it crashes. The odd thing is that it will consistently crash on the same exact line every time (so it doesn't seem to be a memory pressure issue). I can't find any ryhm or reason behind any of this. Here are a few examples of crashes:

  • for key in dict.keys {} but not for (key, _) in dict {}.
  • dateFormatter.date(from:) but not just dateFormatter.
  • attributes.count where attributes is a custom struct.
  • existingObjects.insert(newObject, at: 0) but not existingObjects.append(newObject)

I haven't seen the crash on my iPhone 6, but my iPad Air 2, iPhone 6s Plus and iPhone 7 all consistently crash on the same line until I make a change, which moves the crash to a new point in the code.

David Beck
  • 10,099
  • 5
  • 51
  • 88
  • It would be helpful if you get the crash logs. You can also install `console.app` to see what the crash is all about. While running on the device, check the Xcode devices. It will also hold the crash log. – Sachin Vas Sep 29 '16 at 16:16

1 Answers1

3

After quit a bit of research I finally stumbled onto the answer: https://forums.developer.apple.com/thread/60632.

It is indeed an out of memory error. I was seeing only 5mb in Xcode instruments and thought it couldn't possibly killing the process for so little memory, but NotificationService extensions have a very low memory limit and the frameworks I was linking against started the process out at around 4mb. It was just a matter of time before something tipped the scales.

David Beck
  • 10,099
  • 5
  • 51
  • 88
  • My iPhone 6 is fine, but when I test an iPhone 7 it starts up at 4.9mb and crashes immediately. Did you end up scrapping the whole service extension, or did you find a way out? – iantheparker Oct 20 '16 at 18:52
  • 3
    I ended up simplifying the extension significantly. My first approach was to link to my non UI framework and do a network request to get notification details and also save that info to my Core Data store so I didn't have to request the data again. Given the extreme memory limitations, I'm now providing that content in the push body itself and not linking to any frameworks. – David Beck Oct 22 '16 at 01:08