Ionic how to fire a function just before app is closed?

I'm using ionic and I would like to run a function to clear my localstorage once a user triggers an event to close the app.

Does ionic have a built in on app close function? Something like

$ionicPlatform.close(function() {
   // code to clear localstorage
})

Can you just clear on suspend of the app and reload on resume?