blub
blub

Reputation: 359

iOS 8 - How to get LocalNotification playing Sound when App is in Background?

I need to have some Alarm-Clock Functionality in my App.

One of them should be to let the Phone playing Sound when the LocalNotification fires and the App is in the Background.

With iOS 7.1 everything works fine but in iOS8 no Sound is playing anymore until the App is back in Foreground.

At the Moment i'm using the AudioToolbox/AudioServices.h Class.

How can i fix that ?

Upvotes: 0

Views: 1807

Answers (3)

Roman Bambura
Roman Bambura

Reputation: 177

.caf fine doesn't play with local notification on real device. If you change .caf to .aiff you'll notification with sound!

Upvotes: 0

blub
blub

Reputation: 359

It seems to be a bug within Xcode Simulator for iOS8. With Xcode Simulator for iOS7.1 AND/OR iOS8 "real" Device everything works fine.

Upvotes: 1

Mital Solanki
Mital Solanki

Reputation: 2474

This code may be help you...

Register Notification Settings

- for Objective c

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]]

        return YES;
    }

- for Swift

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool 
    {
        application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound|UIUserNotificationType.Alert |UIUserNotificationType.Badge, categories: nil)   

        return true
    }

Upvotes: 2

Related Questions