5 Replies Latest reply on Mar 1, 2012 4:47 PM by rightnut52

    Notification ANE in background

    Smosti

      Hello

      Is there any way to dispatch a notification using the Notification ANE

      while an app is in the background (not visible) in an iOS device?

       

      Im running a Timer that send the notification once it hits 0, but when the

      app is minimized (not closed) the timer is frozen.

       

      Any ideas?

        • 1. Re: Notification ANE in background
          Arthy the crab Level 1

          searching for the same answer .......

          • 2. Re: Notification ANE in background
            Smosti Level 1

            I've come to the conclusion that it would be a "local notificiation" but I still haven't been able to find anything of the sort...

            • 3. Re: Notification ANE in background
              rightnut52

              i need this to work also. any luck figuring this out??? timers made with AIR are almost useless without this feature. i didn't realize AIR was this helpless on iOS.

               

              one option is to force the app to stay awake when it is in the foreground:

              NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;

              (this works for me on ipod touch4 iOs5 air 3.1)

               

              then use:

              stage.addEventListener(Event.DEACTIVATE, onAppDeactivate);

              to send an ANE notification to the user when the user moves the app to the background. it could inform the user that the timer will not work unless brought back into the foreground. silly, i know!

               

              instead of this ridiculous workaround, could the current notification ANE be altered to include a timer notification option. or do ANE's get paused like the rest of the air apps?

               

              if not...

               

              can iOS communicate with AIR through sockets? if so, maybe we could send the actual time (the time that the alarm should sound) through a socket and write a small bit of native objective-c to call a notification at that time. James Ward did this with android before ANE's came out: http://www.jamesward.com/2011/05/11/extending-air-for-android/

              • 4. Re: Notification ANE in background
                Smosti Level 1

                So far i've narrowed it down to the following:

                 

                A "UILocalNotification" ANE is necesary, however I have not been able to find any that work.

                The workaround would be to create a localNotification and destroy it accordingly with the push of the button or the actual

                timer event. If you find any ANEs that work with this O-C object please do let me know.

                • 5. Re: Notification ANE in background
                  rightnut52 Level 1

                  i have this working for the most part after some tinkering. and i was all ready to give up hope!

                   

                  i thought that if i couldn't get notifications to work when my app is in the background, i would try to get a background audio alarm to work (using my own audio within the app, not the notifcation audio alert sound).

                   

                  i found this post:

                  http://stackoverflow.com/questions/6457894/air-2-7-for-ios-playing-audio-in-the-background

                   

                  i changed my -app.xml <iphone> section to include UIBackgroundModes for audio:

                   

                    <iPhone>

                      <InfoAdditions>    

                        <![CDATA[

                           <key>UIDeviceFamily</key><array><string>1</string></array>

                           <key>UIBackgroundModes</key><array><string>audio</string></array>

                              ]]>

                      </InfoAdditions>

                      <requestedDisplayResolution>high</requestedDisplayResolution>

                    </iPhone>

                   

                   

                  this actually worked for me (ipod touch4 iOs5 air 3.1). and strangely enough, it made my notifications work as well! i have no idea why.

                  my audio alarm now sounds and a notification pops up. without adding my own sound, the notification will NOT pop-up.

                   

                  i created a button that sets a timer that goes off in 5 seconds. i push the button and move the app to the background quickly. the timer calls:

                  notifyUser();

                  myAlarm.play();

                   

                  so now, a timer IS working in the background as long as a sound is attached to it. weird.

                   

                  one flaw is it doesn't work the first time. the 2nd attempt and onward work perfectly. what the hell is that?