Appcelerator notification IOS 8 - no sound

710 views Asked by At

Im using appcelerator 4.0.0. I have downloaded the code of this appcelerator toturial and tried to add sound to the notification. http://www.appcelerator.com/blog/2014/09/new-in-sdk-3-4-ios-8-interactive-notifications/

However I cant seem to get the sounds working. The notification settings/permissions on the device are good. I have tested on simulator and real device.

var notif = Ti.App.iOS.scheduleLocalNotification({
    date: new Date(new Date().getTime() + 5000), // send it in 5 sec
    alertBody: 'This is your message',
    badge: 1,
    sound: 'default',
    userInfo: {"url": "http://www.download.com/resource/asset.json", id:"1"},
    category: "DOWNLOAD_CONTENT"
});  
3

There are 3 answers

3
kopiro On

Wait, there are some misunderstandings in your code.

Ti.App.iOS.scheduleLocalNotification schedule a notification, but if you set date = new Date(new Date().getTime()), the app is still in foreground... and when the app is in foreground, no iOS banner is shown = no sound.

So, what you have to do is date: new Date(Date.now() + 5000), and close the app.

0
Ali Akram On

For devices running iOS 8 and later, you need to register the application to use the local notification services. Use the Titanium.App.iOS.registerUserNotificationSettings() method to enroll the application in local notification services. Pass the method a dictionary with the types property set to an array of notification types to use.

Titanium.App.iOS.USER_NOTIFICATION_TYPE_ALERT: allow the application to display an alert or banner message. Titanium.App.iOS.USER_NOTIFICATION_TYPE_BADGE: allow the application to modify the badge value in the application's icon. Titanium.App.iOS.USER_NOTIFICATION_TYPE_NONE: disable application UI notifications. The application will still be notified of the notification by the notification event. Titanium.App.iOS.USER_NOTIFICATION_TYPE_SOUND: allow the application to play a sound.

if (Ti.Platform.name == "iPhone OS" && parseInt(Ti.Platform.version.split(".")[0]) >= 8) {
Ti.App.iOS.registerUserNotificationSettings({
    types: [
        Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT,
        Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND,
        Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE
    ]
});

}

0
TheFuquan On

I did experience the same issue and i'm using the Ti sdk 5.2.0.GA, apparently no sound is played unless it s explicitly set for the attribute sound.

So my workaround was:

search for the default notification sound file on the internet and use it under the app/assets/iphone folder.

var notif = Ti.App.iOS.scheduleLocalNotification({
    date: new Date(new Date().getTime() + 5000), // send it in 5 sec
    alertBody: 'This is your message',
    sound: '/default-notif.m4r'
)};

Hope this helps!