0

私のプロジェクトの3つの音:

} - (IBAction)Sound1:(NSDate *) fireDate;

{

  [[NSUserDefaults standardUserDefaults] setObject:@"Sound1.aiff" forKey:@"UserSoundChoice"];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
[localNotification setFireDate:[NSDate date]];
[localNotification setTimeZone:[NSTimeZone defaultTimeZone]];
[localNotification setAlertBody:@"Alarm went off!"];   
[localNotification setAlertAction:@"View"]; 
[localNotification setHasAction:YES]; 
localNotification.soundName= [[NSUserDefaults standardUserDefaults] objectForKey:@"UserSoundChoice"]; 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
}
- (IBAction)Sound2:(NSDate *) fireDate;
{
  [[NSUserDefaults standardUserDefaults] setObject:@"Sound2.aiff" forKey:@"UserSoundChoice"];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
[localNotification setFireDate:[NSDate date]];
[localNotification setTimeZone:[NSTimeZone defaultTimeZone]];
[localNotification setAlertBody:@"Alarm went off!"];   
[localNotification setAlertAction:@"View"]; 
[localNotification setHasAction:YES]; 
localNotification.soundName= [[NSUserDefaults standardUserDefaults] objectForKey:@"UserSoundChoice"]; 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
}
- (IBAction)Sound3:(NSDate *) fireDate;
{
       [[NSUserDefaults standardUserDefaults] setObject:@"Sound3.aiff" forKey:@"UserSoundChoice"];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
[localNotification setFireDate:[NSDate date]];
[localNotification setTimeZone:[NSTimeZone defaultTimeZone]];
[localNotification setAlertBody:@"Alarm went off!"];   
[localNotification setAlertAction:@"View"]; 
[localNotification setHasAction:YES]; 
localNotification.soundName= [[NSUserDefaults standardUserDefaults] objectForKey:@"UserSoundChoice"]; 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
- (IBAction)SetDatePicker
{

NSDateFormatter *dateFormatter =[ [NSDateFormatter alloc] init];
dateFormatter.timeZone = [NSTimeZone defaultTimeZone];
dateFormatter.timeStyle = NSDateFormatterShortStyle;
dateFormatter.dateStyle = NSDateFormatterShortStyle;

NSString *dateTimeString = [dateFormatter stringFromDate: dateTimePicker.date];
NSLog (@"Alarm saved: %@", dateTimeString);

[self Sound1:dateTimePicker.date];
[self Sound2:dateTimePicker.date];
[self Sound3:dateTimePicker.date];

}

-(void)scheduleLocalNotificationWithDate:(NSDate *)fireDate   

{
UILocalNotification *notification =[[UILocalNotification alloc]init];

   notifiction.FireDate = fireDate; 

   notifiction.AlertBody = @"Wake Up!!!";    

  notifiction.soundName =UILocalNotificationDefaultSoundName;   

  notifiction.repeatInterval= NSMinuteCalendarUnit;   

[[UIApplication sharedApplication] scheduleLocalNotification: notifiction];

}

ユーザーがそれらのいずれかを選択して通知音として設定できるようにしたい よく検索してきましたが、私を助ける解決策が見つかりませんでした

4

1 に答える 1

1

ローカル通知とプッシュ通知の音声ファイルを指定できます。ユーザーが警告音として使用するファイルを選択できるようにします。その設定を NSUserDefaults に保存してから、サウンドで UILocalNotification を作成します。

例:

Xcode プロジェクトに 3 つのサウンド ファイル (Sound1.aiff、Sound2.aiff、Sound3.aiff など) を含める必要があります。

- (IBAction)Sound1
{
    [[NSUserDefaults standardUserDefaults] setObject:@"Sound1.aiff" forKey:@"UserSoundChoice"];
    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    [localNotification setFireDate:[NSDate date]];
    [localNotification setTimeZone:[NSTimeZone defaultTimeZone]];
    [localNotification setAlertBody:@"Alarm went off!"];   
    [localNotification setAlertAction:@"View"]; 
    [localNotification setHasAction:YES]; 
    localNotification.soundName= [[NSUserDefaults standardUserDefaults] objectForKey:@"UserSoundChoice"]; 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
}

出典: iPhoneのプッシュ通知音に制限?

カスタムサウンドを再生するUILocalNotifications

https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/WhatAreRemoteNotif.html#//apple_ref/doc/uid/TP40008194-CH102-SW1

于 2013-08-06T23:56:01.007 に答える