2011-07-21 14 views
0

私は時計アプリでローカル通知を実装したいと思います。基本的には、30分ごとにチャイムが再生される船の時計のように30分ごとに音楽ファイルを再生する必要があります。ローカル通知を初期化する方法は?

誰でも、アプリがバックグラウンドで入力されてもこの機能を実装する方法を大まかに知ることができますか?

答えて

1

私は最近、ローカル通知のものを使用し、以下の機能

//ローカル通知に

scheduleNotificationWithItemが

- (void)scheduleNotificationWithItem:(NSDictionary*)item { 

    UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 

    if (localNotification == nil) return; 

    localNotification.fireDate = [item valueForKey:FIRE_TIME_KEY]; 

    localNotification.timeZone = [NSTimeZone defaultTimeZone]; 

    localNotification.alertBody = [NSString stringWithFormat:NSLocalizedString(@"%@", nil), [item valueForKey:NOTIFICATION_MESSAGE_KEY]]; 

    localNotification.alertAction = NSLocalizedString(@"View Details", nil); 

    localNotification.soundName = UILocalNotificationDefaultSoundName; 

    localNotification.userInfo = item; 

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

    [localNotification release]; 
} 

最後にあなたが扱うことができるように定義されて

for (int i= 1 ; i<=10; i++) { //We here set 10 Notification after every 30 minutes from now you can modify it accordingly 

    NSDate *scheduled = [[NSDate date] dateByAddingTimeInterval:60*30*i]; //These are seconds 

    NSDictionary* dataDict = [NSDictionary dictionaryWithObjectsAndKeys:scheduled,FIRE_TIME_KEY,@"Background Notification received",NOTIFICATION_MESSAGE_KEY,nil]; 

    [self scheduleNotificationWithItem:dataDict]; 

} 

の設定を使用しましたこれらの通知は、

開発者向けドキュメントを読ん
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { 

// Do the required work you can obtain additional Info via notification.userInfo which happens to be a dictionary 

} 

を次のようにあなたがこれらの通知を扱うことができる210はそれが私が現在の日付にと日付を設定したいが、問題は、私が欲しいということです

+0

ねえ、今日はそれを試していただきありがとうございます。 – leena

+0

通知が発生したときに任意の関数を呼び出すことが可能です – leena

+0

サウンドだけを再生したい場合はlocalNotification.soundName = FILENAME; (再生するアプリのバンドル内のリソースの名前)、アプリケーションから通知を受け取ったときにこのサウンドが再生されます –

0

あなたの要件に従って、UILocalNotificationsを使用して 'firedate'を設定し、通知をスケジュールすることができます。これらの通知は、アプリが実行中であるかバックグラウンドであるかにかかわらず、常にalertviewのように表示されます。

+0

役立ちますあなたはより多くのstuff.Hopeを理解するのに役立ちます1:00,1:30,2:00,2:30などのように30分ごとにローカル通知を受けるようにしてください。 – leena

関連する問題