2011-08-01 12 views
7

私はアラームアプリケーションを作成しようとしましたが、iTunesからローカル通知の音に曲を設定する方法がわかりません。iTunesの曲からサウンドローカル通知を設定するにはどうすればいいですか?

は今、私はこのようなローカル通知の外観について

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.section == 0) { 
     MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic]; 

     picker.delegate = self; 
     picker.allowsPickingMultipleItems = NO; 
     picker.prompt = NSLocalizedString (@"Select any song from the list", @"Prompt to user to choose some songs to play"); 

     //[self presentModalViewController: picker animated: YES]; 
     [self.navigationController pushViewController:picker animated:YES]; 

     NSLog(@"gsudifghukdsf"); 
     [picker release]; 

    } 
} 

- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection 
{ 
    [self.navigationController popToRootViewControllerAnimated:YES]; 
    //[self dismissModalViewControllerAnimated: YES]; 
    NSLog(@"%@",mediaItemCollection); 

    UILocalNotification *local = [[UILocalNotification alloc] init]; 
    //selectedSongCollection=mediaItemCollection; 

} 

- (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker 
{  
    [self.navigationController popToRootViewControllerAnimated:YES]; 
    //[self dismissModalViewControllerAnimated: YES]; 
} 

のiTunes

と何かを呼び出すために、このコードを使用し

UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
    if (localNotif == nil) 
    { //NSLog(@"Get in if localNotif"); 
     return; 
    } 

    localNotif.fireDate = DateAlarm; 

    localNotif.timeZone = [NSTimeZone defaultTimeZone]; 

    // Notification details 
    localNotif.alertBody = [NSString stringWithFormat:@"%@",DateAlarm]; 
    // Set the action button 
    localNotif.alertAction = @"Oh Shit"; 



    localNotif.soundName = UILocalNotificationDefaultSoundName; 

だから私は地元の音に曲を設定することができますどのように私を導いてください??

+0

ガイドしてください。それともできない? – crazyoxygen

+0

このURLで確認してくださいhttp://www.techotopia.com/index.php/Scheduling_iOS_4_iPhone_Local_Notifications#Adding_a_Sound_File_to_the_Project –

答えて

9

メインバンドルの一部であるサウンドは、アプリストアに送信されたときにアプリのビルドに含まれていることを意味します。

はい、サウンドを録音したり、サウンドをダウンロードしたりすることはできますが、アプリケーションのバンドルに含まれていないため、作成/保存されたファイルは使用できません。アプリがバンドルの外でカスタムサウンドを使用してそれを使用している場合は、プライベートAPIを使用しています。私を信じて、私は考えることができるすべてのオプションを試しました。

+0

私はこの正確なことを行うアプリを見ました。例、[Rise](https://itunes.apple.com/us/app/rise-alarm-clock/id577221529)どのように彼らはそれを行うか?彼らはいくつかのサウンド処理を行うようだが、私は確信していない。 – r3dsm0k3

+0

彼らのやり方は分かりません。現在の[UILocalNotificationクラスリファレンス](http://developer.apple.com/library/ios/#documentation/iPhone/Reference/UILocalNotification_Class/Reference/Reference.html)と[ローカルとプッシュ通知プログラミングガイド](http: /developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp。html#// apple_ref/doc/uid/TP40008194-CH103)は、Main Bundleのサウンドでしか実行できないと言っています。だから、彼らがメインバンドルの音を詰める方法を見つけていなければ、私は考えていない。 :( – thephatp

2

@thephatpで指摘されているように、通知(ローカルまたはリモート)は、アプリケーションバンドルにあるサウンドの再生のみをトリガーできます。私はこれを回避する方法を見ません。

@ r3dsm0k3は、どのアプリがアプリのバンドルに含まれていないサウンドを再生するかを彼のコメントで尋ねます。RiseIf I had to guess, I would say that Rise registers itself as an app requiring the audio background mode:アプリのサポートされているバックグラウンドタスクバックグラウンド実行のいくつかのタイプの

サポートを宣言

は、それらを使用することにより、アプリ 事前に宣言する必要があります。アプリはInfo.plistファイルを使用して サービスのサポートを宣言します。 あなたのInfo.plistファイルにUIBackgroundModesキーを追加し、次の文字列のいずれか 以上を含む配列に値を設定します。

オーディオ 背景にしながら、アプリがユーザーに可聴コンテンツを再生します。 (このコンテンツは、ストリーミングオーディオやビデオコンテンツ のAirPlayを使用しています。)

は、これは効果的にその上昇がすべての時間を実行しているとどまることを許されていることを意味します。これは、ユーザーのためにオーディオを再生するため、許可されています。それは時間の100%オーディオを再生しないことはアップルの問題ではないようです。

ライズはUILocalNotificationsを使用しても使用しなくてもかまいません。ほとんどの場合、アプリはアンロードされたときにのみバックアップとして使用され、別のタイマーメカニズムを使用してウェイクアップアラームシーケンスをトリガーします。

関連する問題