2012-02-21 8 views
3

iPhoneが眠っているときにアラーム音を鳴らす方法を知っていますか? iPhoneの時計アプリに似ていますか?iPhone - バックグラウンドでアプリを開いている間にアラーム音を鳴らす

非常に重要EDIT:内蔵のiPhone
で時計アプリのアラーム音が再生されているときで

、ユーザーは
、サイレント(振動モード)にサイレントスイッチを切り替えると、アラーム音は依然として継続遊ぶ。

あなたは同じことをする方法を知っていますか?

+0

のパスを配置する必要があり、ドキュメントフォルダ内にある、[私のスレッド]をチェックしてください9725192/i-mode-locked-in-ios-6のオーディオ) –

答えて

0

方法のみが設定されたボタンをスケジュールするUILocalNotificationクラスを使用してビューコントローラにscheduleNotificationと呼ばれる方法を実行するように配線されている音が30秒間再生することを可能にする..both local NotificationsまたはPush notifications

+0

応答のためのShubhankに感謝します、私の編集の質問を参照してください! –

+0

内蔵アプリ(ネイティブiOSアプリ)には、サードパーティのiOSアプリには制限がありません。つまり、ユーザーがサイレントモードに切り替えるとアプリのサウンドは再生されません。 – Shubhank

+0

バックグラウンドのときにサウンドを再生し、ユーザーがサイレントに切り替えるとサイレントにならない:http://itunes.apple.com/us/app/i-qi-singing-bowl-timer-free/id427428211?mt=8、do彼らはどのようにそれを行うことができますか? –

2

を使用することです通知。アプリがバックグラウンドに入る

(void)scheduleNotification 
{ 
    [reminderText resignFirstResponder]; 
    [[UIApplication sharedApplication] cancelAllLocalNotifications]; 
    Class cls = NSClassFromString(@"UILocalNotification"); 
    if (cls != nil) 
    { 
     UILocalNotification *notif = [[cls alloc] init]; 
     notif.fireDate = [datePicker date]; 
     notif.timeZone = [NSTimeZone defaultTimeZone]; 
     notif.alertBody = @"Did you forget something?"; 
     notif.alertAction = @"Show me"; 
     notif.soundName = UILocalNotificationDefaultSoundName; 
     notif.applicationIconBadgeNumber = 1; 
     NSDictionary *userDict = [NSDictionary dictionaryWithObject:reminderText.text 
       forKey:kRemindMeNotificationDataKey]; 
     notif.userInfo = userDict; 
     [[UIApplication sharedApplication] scheduleLocalNotification:notif]; 
     [notif release]; 
    } 
} 
+0

お返事ありがとうPravi、私の編集の質問を参照してください! –

+2

@eeerahul:私の答えと@ Tuyen Nguyenを編集してくれてありがとう:申し訳ありませんが、私はこれについて知っていませんが、私はそれがサイレントモードの仲間で音を再生できないと思います。あなたが本当に私に感謝したい場合は、上向き矢印ボタンをクリックしてください。 –

+0

@TuyenNguyen:音のモードを変えることができれば、あなたは今までに何ができるのかを知ることができます。最高の運 –

1

前に、AVAudioPlayerを使用してサイレントサウンドを再生し、それが無限の回数を果たし続ける:コードは次のように見えます。通知が開始されると、AVAudioPlayerを使用して通知音を再生し、UILocalNotificationオブジェクトは再生しません。それは私のために働いた。

1

i-qiアプリを見ると、彼らのinfo.plistでUIBackgroundModesを "audio"に設定している可能性が最も高いです。これは、彼らがバックグラウンドでオーディオを再生できることを意味します。バックグラウンドのオーディオセッションが使用されていない場合、セッションが切断されるため、タイマーが終了するまでサイレントオーディオを再生している可能性があります。

サイレントスイッチに関しては、おそらく使用しているセッションカテゴリに基づいています。このリソースをチェックアウト: http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionCategories/AudioSessionCategories.html#//apple_ref/doc/uid/TP40007875-CH4-SW1

3

このコードは、バックグラウンドで音楽を再生するのに役立ちます: 音楽のサウンドファイルは、わずか30秒 通知サポート30秒の音声ファイルである必要があり、場合には、バンドルフォルダにする必要がありますそれはhttp://stackoverflow.com/questions/(そして、あなたは私があまりにも数ヶ月のために、このにされてきたサウンドファイル

NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; 
NSString *dateValueRemaining =[NSString stringWithFormat:@"23/08/2012 11:30:33"]; 
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 
[dateFormat setDateFormat:@"dd/MM/yyyy HH:mm:ss"]; 
NSDate *dateRemaining = [dateFormat dateFromString:dateValueRemaining]; 
NSDate *pickerDate = dateRemaining; 
NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit 
                 | NSMonthCalendarUnit 
                 | NSDayCalendarUnit) 
               fromDate:pickerDate]; 
NSDateComponents *timeComponents = [calendar components:(NSHourCalendarUnit 
                 | NSMinuteCalendarUnit 
                 | NSSecondCalendarUnit) 
               fromDate:pickerDate]; 
// Set up the fire time 
NSDateComponents *dateComps = [[NSDateComponents alloc] init]; 
[dateComps setDay:[dateComponents day]]; 
[dateComps setMonth:[dateComponents month]]; 
[dateComps setYear:[dateComponents year]]; 
[dateComps setHour:[timeComponents hour]]; 
[dateComps setMinute:[timeComponents minute]]; 
[dateComps setSecond:[timeComponents second]]; 
NSDate *itemDate = [calendar dateFromComponents:dateComps]; 
NSLog(@"itemDate: %@", itemDate); 
if (localNotif) { 
    [[UIApplication sharedApplication] cancelLocalNotification:localNotif]; 
} 
localNotif = [[UILocalNotification alloc] init]; 
if (localNotif == nil) { 
    return; 
} 
UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
localNotif.fireDate = itemDate; 
localNotif.timeZone = [NSTimeZone defaultTimeZone]; 
localNotif.alertBody = @"Your Time is Over"; 
localNotif.alertAction = @"View"; 
//---THIS SONG FILE IN THE NSBUNDLE FOLDER---------// 
localNotif.soundName = @"s1.mp3"; 
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"]; 
localNotif.userInfo = infoDict; 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 
関連する問題