Play local notification default sound when displaying UIAlertView?

前端 未结 4 1393
不知归路
不知归路 2020-12-04 10:19

I\'m writing a reminders app for iPhone that displays reminders using local notifications.

If a reminder goes off while the application is running, the local notific

4条回答
  •  情话喂你
    2020-12-04 10:47

    Set delegate in .h file:

    @interface ViewController : UIViewController 
    {
    }
    
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
    
    @end
    

    And set method that above declared.

    And in .m file do this:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/ma.mp3", [[NSBundle mainBundle] resourcePath]]];
    
        NSError *error;
    
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
    
        audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
        audioPlayer.numberOfLoops = -1;
    
    
        [audioPlayer play];
    
        [alert show]; 
    }
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
        if (buttonIndex==0) {
            [audioPlayer stop];
    
        }
        NSLog(@"U HAVE CLICKED BUTTON");
    }
    

提交回复
热议问题