Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by bastianmeyerbm3 · Aug 28, 2018 at 10:18 AM · iosmobilenotificationbattery

Unity mobile "Low Battery" notification problem (IOS)

Hi,
currently i'm working an on app for IOS and Android. Its an online game that connects to the server all 3 to 5 sec. If the user closes the app completely (so OnApplicationExit() gets called) the user gets kicked out of the game room.If the user softcloses the app (so OnApplicationPause() gets called) the same result should happen, and i works.

But last time testing it on my IPhone i got the "Low Battery" notification what calls the OnApplicationPause() func. too and kicks the player what shouldnt happen.

How can i solve the problem with the notification? Is there a better alternative than OnApplicationPause()?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by JVene · Aug 28, 2018 at 11:30 AM

OnApplicationPause is filled with exceptions to the rule (read the docs on it). Frankly, it's a bit of a mess. The behavior is platform dependent, which is a warning to me that the message isn't reliable (if it behaves differently by platform, it could very well behave differently in different or future versions of one platform - experience suggests it).


I don't find documentation on a battery low message, but you might experiment by adding an OnApplicationFocus to see if there's a pattern you can recognize. I doubt it, but maybe iOS sends some focus transition you might recognize.


Otherwise, inside OnApplicationPause, read the SystemInfo.batterylevel. You have to make a judgment call here. The level Unity returns is from 0 to 1, which is to say that 0.10 is 10% battery, 0.15 is 15% battery. You have to select a level that makes sense. If at or below some threshold, assume this is a battery low system message, and skip that code which you want to avoid.


As a side note, it is unfortunate, and sometimes you can't avoid it, but when you can you should avoid platform specific behavior even if that means you have leave the play "not" kicked out on all pauses, just so the app behaves well at battery low pause. This seems to me one of those occasions where you have to prioritize overall behavior over that you'd prefer by design, leaving what is most logical. Since the pause behavior is given to you by the device/platform, you can't really stop that. It seems intercepting and interpreting accurately why pause is called does not work in all occasions, so I'd say kicking the player out on pause should not be dependent on why pause is called, since it is going to be unreliable. Checking battery status might help, but you can't be sure if the status happens to be coincident with a player pause.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bastianmeyerbm3 · Aug 28, 2018 at 02:57 PM 0
Share

Okay, thank you! Would be cool if unity added a state for "local notifications" like calls, low battery messages etc.

avatar image JVene bastianmeyerbm3 · Aug 28, 2018 at 06:07 PM 0
Share

In a sense, those are available, but Unity isn't where you get that. When you want something native, you go native. There is a tendency for students to think only Unity commands and messages are available, because it is a Unity application, but in reality you're writing a C# application that is driven by and consumes the Unity framework. You can make any call you like, though it is much more difficult to read native messages, you are able to write native plugins for each platform (it is an advanced concept)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

158 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get current battery life on mobile device 3 Answers

Disable/enable local notifications on Android and iOS 0 Answers

Unity 3.5 allows terrains on iPad2 and newer iOS devices, what's the max terrain size? 0 Answers

Game view performance VS actual build performance 2 Answers

Maximum RAM memory exceeded causes app to crash in iOS 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges