IOS Play Sound on receiving push notification when app in foreground

后端 未结 1 370
傲寒
傲寒 2020-12-19 17:07

How to play sound on receiving a push notification when the app is in the foreground state.

My Code :

- (void)application:(UIApplication *)applicatio         


        
相关标签:
1条回答
  • 2020-12-19 17:31

    Instated of AVPLayer, you should try with following code:

    Add following framework

    #include <AudioToolbox/AudioToolbox.h>
    

    And use this code,

        SystemSoundID soundID;
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef ref = CFBundleCopyResourceURL(mainBundle, (CFStringRef)@"mySoundName.wav", NULL, NULL);
        AudioServicesCreateSystemSoundID(ref, &soundID);
        AudioServicesPlaySystemSound(soundID);
    
    0 讨论(0)
提交回复
热议问题