How to make a local notification alert with sound

224 views Asked by At

I want to set sound in local notification when my app in foregroundmode. i m try lot of thing . please help me.

      UInt32 flag = 0;
   SystemSoundID soundID;
        int err = AudioServicesSetProperty(kAudioServicesPropertyIsUISound,
                                       sizeof(UInt32),
                                       &UILocalNotificationDefaultSoundName,
                                       sizeof(UInt32),
                                       &flag);

        NSLog(@"%d",(unsigned int)err);

        AudioServicesPlaySystemSound(soundID);
1

There are 1 answers

0
uraimo On

If you are trying to launch a local notification with a sound you can use the soundName property:

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = [NSDate dateWithTimeIntervalSinceNow:30];
localNotif.alertBody = @"Hey!";
localNotif.alerttitle = @"Notification!";

localNotif.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

With UILocalNotificationDefaultSoundName the notification will use the default sound, use a filename instead for a custom sound.

More on this property in the documentation.