Is possible to keep running code in phones while application is backgrounded?

i’ve tried to check the “run in background” checkbox but obviously does not work on phones, am i able to keep running code? for example i wanna check some things and if something happens make the phone vibrate even if the application is backgrounded, is this possible?

for example i’ve tried this in my phone

function OnApplicationPause() {

	iPhoneUtils.Vibrate();
	yield WaitForSeconds(3.0);
	iPhoneUtils.Vibrate();

}

the first vibrate is always executed when application loses focus, but the second vibrate is only executed when the application regains focus, so basically i need to run code even if the application is not focused, is there a way? avoid pausing or run code even if paused? thank you all

It depends on your platform.

In Android, yes you can. However, I do not know if Unity handles the background running natively or if you need to make a plugin for the app.

In iOS, not really. While yes, there is limited multitasking (multi-apps-running-at-the-same-time) support for iOS, the general behavior is to exit the application when the home button is pressed.

I don’t really have experience with this so you might need to do some digging and you might need to make some plugins.