distriqt / airnativeextensions

DEPRECATED: Original repository of the distriqt native extensions and is no longer maintained. Please see our site for the latest ANEs
https://airnativeextensions.com
2 stars 0 forks source link

local notification #240

Closed tamaker closed 9 years ago

tamaker commented 9 years ago

audible file (fx05.caf) not playing with local notification ane.

flash builder 4.6 premium, running latest air sdk beta and ios 8 running on an iphone 5s and ios 7.2.1 running on an iphone 4s. when using the mxml found below and exporting release build from mac book pro running mavericks (and including the ios8 sdk in the build) I dont get the audio file (taken from the ane example (fx05.caf) to play -- but notification shows fine and vibration works fine...just NOT the audible sound for the local notification.

the latest build (as of 10/18) installs file (prior to that in working with Michael on it, I had intstall problems / issues but they are worked out and now I just still dont get the sound to play at all.

heres the mxml Im using:

<?xml version="1.0" encoding="utf-8"?> <s:View xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView" creationComplete="init()">

<fx:Script>
    <![CDATA[

        protected function init():void{
            trace('running init() now...');
            this.addEventListener(Event.ADDED_TO_STAGE, prepNotify);
            NativeApplication.nativeApplication.systemIdleMode=SystemIdleMode.KEEP_AWAKE;
            NativeApplication.nativeApplication.executeInBackground = true;
        }

        protected function prepNotify(e: Event):void{
            trace('running prepNotify() now...');
            testNotifications();
        }

        //////////////////////////////////////////////////////////
        // NOTIFICAITONS RELATED CODE
        //////////////////////////////////////////////////////////
        import com.distriqt.extension.notifications.Notification;
        import com.distriqt.extension.notifications.NotificationIconType;
        import com.distriqt.extension.notifications.NotificationRepeatInterval;
        import com.distriqt.extension.notifications.Notifications;
        import com.distriqt.extension.notifications.events.NotificationEvent;

        public var msgTitleLine: String = "Hello World";
        public var msgBody: String = "The web is my friend, but sometimes I hate it.  My brain hurts.";
        public var msgdbID: String = int(Math.random() * 100) as String;

        private function testNotifications(): void {
            try {
                Notifications.init("MY COOL KEY HERE... GET YOUR OWN!!!");
                Notifications.service.addEventListener(NotificationEvent.NOTIFICATION_DISPLAYED, notifications_notificationDisplayedHandler, false, 0, true);
                Notifications.service.addEventListener(NotificationEvent.NOTIFICATION_SELECTED, notifications_notificationSelectedHandler, false, 0, true);

                Notifications.service.addEventListener(NotificationEvent.NOTIFICATION_DISPLAYED, notifications_notificationDisplayedHandler, false, 0, true );
                Notifications.service.addEventListener(NotificationEvent.NOTIFICATION_SELECTED,  notifications_notificationSelectedHandler,  false, 0, true );

            } catch (e: Error) {
                trace("NOTIFICATION ERROR:" + e.message);
            }
        };

        ////////////////////////////////////////////////////////
        //  SENDING NOTIFICATION...
        //////////////////////////////////////////////////////////
        private var _count: int = 0;

        private function sendNotification(): void {
            var notification: Notification = new Notification();
            notification.id = int(Math.random() * 100);
            notification.tickerText = msgTitleLine 
            notification.title = msgTitleLine 
            notification.body = "NEW Test Notification Here: " + msgTitleLine 
            notification.iconType = NotificationIconType.APPLICATION;
            notification.count = 0;
            notification.vibrate = true;
            notification.playSound = true;
            notification.soundName = "fx05.caf";
            notification.delay = 1;
            notification.data = "Some notification data to attach " + notification.id;

            try {
                Notifications.service.notify(notification.id, notification);
                _count++;
                Notifications.service.setBadgeNumber(_count);
                trace("sendNotification():sent:" + notification.id);
            } catch (e: Error) {
                trace("ERROR:" + e.message);
            }
        }

        ////////////////////////////////////////////////////////
        //  NOTIFICATION EVENT HANDLERS
        //////////////////////////////////////////////////////////
        private function mouseClickHandler(event: MouseEvent): void {
            sendNotification();
        }
        private function notifications_notificationDisplayedHandler(event: NotificationEvent): void {
            trace(event.type + "::[" + event.id + "]::" + event.data);
        }
        private function notifications_notificationSelectedHandler(event: NotificationEvent): void {
            trace("USER SELECTED NOTIFICATION!!! " + event.type + "::[" + event.id + "]::" + event.data);
            try {
                _count--;
                Notifications.service.cancel(event.id);
                Notifications.service.setBadgeNumber(_count);
                //Notifications.service.cancelAll();
            } catch (e: Error) {}
        }
    ]]>
</fx:Script>

<s:VGroup y="0" width="100%" height="100%" horizontalAlign="center" horizontalCenter="0"
          textAlign="center" verticalAlign="middle">

    <s:HGroup width="200" height="20%" horizontalAlign="center" verticalAlign="bottom">
        <s:Button id="myBtn" label="Get Random Number" click="sendNotification()"/>
    </s:HGroup>

</s:VGroup>

/s:View

marchbold commented 9 years ago

Hi,

Firstly can you check that the file is included in the packaging options:

File / Properties / Build Packaging / Apple iOS / Package Contents

Make sure the caf file is selected.

Secondly, you are aware that the sound only plays when the notification is displayed while the application isn't running in the foreground. i.e. if you get the NOTIFICATION_DISPLAYED event no sound will be played.

Lastly can you send me your device console logs?

Cheers

tamaker commented 9 years ago

Michael this works fine now.... thanks for your help with it.... seems to have been related to the update to latest air beta and inclusion of ios 8 sdk.

marchbold commented 9 years ago

Ah good to hear,

Good luck with your app.