Search Issue Tracker
By Design
Votes
0
Found in
2018.4.0f1
2018.4.4f1
2019.1.0a1
2019.2.0a1
2019.3.0a1
Issue ID
1172298
Regression
No
[iOS] OnApplicationPause() is not called if "Behaviour in Background" is set to "Custom"
How to reproduce:
1. Open the "PauseRepro.zip" project
2. Switch platform to iOS
3. In the Player settings, set "Behaviour in Background" to "Custom"
4. Build & Launch the app on device
5. Swap the app to background
Actual result: OnApplicationPause() callback doesn't get called and "Pause called" isn't logged into the console.
Expected result: OnApplicationPause() callback gets called and "Pause called" is logged into the console.
Reproducible with: 2019.3.0a11, 2019.2.1f1, 2019.1.14f1, 2018.4.6f1, 2017.4.30f1.
Tested with:
-iPhone 7 (iOS 10.2)
Notes:
- When Behaviour in Background is set to "Custom" the player gets paused when in background.
- Right now this behaviour is set by design, but the callback should get called since the application gets paused.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Keywords on Material Variants aren't automatically saved when changed on original Material through Shader Graph
- Light Probes get baked when calling LightProbes.Tetrahedralize
- Shadows flicker and cause visual artifacts when modifying a GameObject's bounds using Swizzle (Y Mask) and Sine Time nodes
- [WebGL] Frame rate drops by 5-20 fps when moving cursor or touch input in the Player
- Light bleeds when using box shaped spotlight with specific Emission Range values
Resolution Note:
Setting "Behaviour in Background" to "Custom" prevents Unity from pausing so that the Unity loop could be executed native plugins by calling `UnityBatchPlayerLoop` (see https://bitbucket.org/Unity-Technologies/iosnativecodesamples/src/ae6a0a2c02363d35f954d244a6eec91c0e0bf194/NativeIntegration/BackgroundTasks/BackgroundFetch/?at=5.0-dev).
If you don't need to run anything directly in Unity while the app is in background you can add the info.plist key you need from an editor post-processor scripts, in that case you should still pause normally. Something like this should work:
[PostProcessBuild]
public static void OnPostprocessBuild (BuildTarget buildTarget, string path)
{
#if PLATFORM_IOS
if (buildTarget == BuildTarget.iOS) {
var plistPath = path + "/Info.plist";
var plist = new PlistDocument();
plist.ReadFromString(File.ReadAllText(plistPath));
// Get root
var rootDict = plist.root;
PlistElementArray currentBacgkgroundModes = (PlistElementArray) rootDict["UIBackgroundModes"];
if (currentBacgkgroundModes == null)
currentBacgkgroundModes = rootDict.CreateArray("UIBackgroundModes");
}
currentBacgkgroundModes.AddString("fetch");
// Write to file
File.WriteAllText(plistPath, plist.WriteToString());
}
}