Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by MalboM · Mar 31, 2014 at 10:51 AM · iostimetimerlocalpush notification

Time.deltaTime not running in background (for local notification)

Hello, I'm trying to make an app that sends a local notification to the user after some time.

 I tried with time.deltatime:


  

             var startTime = 0.0;
             var tempo1 = 50.0;
             
             
             function Start()
                 {
                   
                     var notif = new LocalNotification();
                     notif.alertBody = "Che ora è?";
                     NotificationServices.ScheduleLocalNotification(notif);
                 }
                 
                 function Update()
                 {
                 
                 
                     
                     startTime += Time.deltaTime;
                     
                     
                     if (startTime >= tempo1) {
            
                       Debug.Log ("About to play aiff.");

                       var notif = new LocalNotification(); 
                       notif.alertAction = "alert";
                       notif.alertBody = "Playing aiff sound";
                       notif.applicationIconBadgeNumber = -1;
                       notif.soundName = notif.defaultSoundName;
                       NotificationServices.ScheduleLocalNotification(notif);
                   
                     
                     }
                 }
 
 

but it seems that the time is not passing while the app is in background

do you have any suggestions? thanks in advance

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

2 Replies

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

Answer by Bunny83 · Mar 31, 2014 at 09:04 PM

If an app is not in the foreground, it doesn't run. Only services can run in the background. Your app is freezed while not active. If you want to schedule a notification you should set the **fireDate** to a point in the future. You can't run your own logic in the background. A Unity-app is a foreground application.

To run something in the background you would need to create a service which isn't possible with Unity. On Android you would need to create this in Java (not UnityScript or Javascript, the real Java) and for iOS you probably need to do this in Objective C in xcode.

However this has nothing to do with Unity and is device specific.

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 MalboM · Apr 01, 2014 at 02:24 PM 0
Share

Thanks a lot Bunny83, It seems that with fireDate now it works

here is how I resolved it:

 function OnApplicationPause(pauseStatus: boolean) {
         
         while(true) {
  
             Debug.Log ("About to play aiff.");
             var notif = new LocalNotification(); 
             notif.alertAction = "alert";
             notif.alertBody = "Playing aiff sound";
             
             notif.fireDate = System.DateTime.Now.AddSeconds(120);
             notif.applicationIconBadgeNumber = -1;
             notif.soundName = notif.defaultSoundName;
             NotificationServices.ScheduleLocalNotification(notif);
                 
             break;
             
         }
     
     }
avatar image Bunny83 · Apr 02, 2014 at 03:05 AM 0
Share

@$$anonymous$$albo$$anonymous$$: Yes that's what i ment, however you don't need the while loop at all. Just create your notification directly in OnApplicationPause.

Could you tick the answer as solution to close the question?

avatar image
0

Answer by frarees · Mar 31, 2014 at 10:55 AM

You can use OnApplicationPause and OnApplicationFocus and deal there with time that has passed whilst on background

Comment
Add comment · Show 1 · 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 MalboM · Mar 31, 2014 at 08:55 PM 0
Share

Thanks a lot for the answer frarees, I tried to use the function OnApplicationPause, but still time doesn't run while the app is in background:

             var startTime = 0.0;
             var tempo1 = 50.0;
  
  
            
  
                 function OnApplicationPause(pauseStatus: boolean)
                 {
  
                     while(true){
  
                     startTime += Time.deltaTime;
  
  
                      if (startTime >= tempo1) {
  
                       Debug.Log ("About to play aiff.");
  
                       var notif = new LocalNotification(); 
                       notif.alertAction = "alert";
                       notif.alertBody = "Playing aiff sound";
                       notif.applicationIconBadgeNumber = -1;
                       notif.soundName = notif.defaultSoundName;
                       NotificationServices.ScheduleLocalNotification(notif);
  
  
                      }
                     }
                 }

did I do something wrong? thanks in advance

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

23 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

Related Questions

Time based scoring 2 Answers

timer that can be reset 1 Answer

Remote Notifications - Triggered by user or not 2 Answers

Vibrate for X time on iOS? 1 Answer

How to work a real life timer? 2 Answers


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