アラーム時間を1時間に設定しました。アプリケーションが実行モードにある場合、アラームは正常に動作しますが、バックグラウンドにある場合、アラームは正しく動作しません。バックグラウンドでアラームを実行するにはどうすればよいですか。
1913 次
2 に答える
2
ローカル通知を使用する必要があります。とても簡単です。詳細については、このドキュメントを参照してください (プッシュ通知はリモート ソースから送信されるため、無視してかまいません)。
于 2012-07-31T04:28:44.093 に答える
1
このコードは、バックグラウンドでアラートとサウンドを使用してlocalNotificationを表示するだけです。そのため、コードとアラームアプリでの使用にいくつかの変更があります。
- (IBAction)Alert:(id)sender{
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"yyyy-MM-dd"];
//NSDate *date = [NSDate date];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate =[NSDate dateWithTimeIntervalSinceNow:15];
localNotif.timeZone = [NSTimeZone localTimeZone];
localNotif.alertBody = @"Emergency";
localNotif.alertAction = @"View";
localNotif.soundName = @"police.mp3";
localNotif.applicationIconBadgeNumber = 1;
localNotif.repeatInterval = NSYearCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
}
于 2012-07-31T04:56:07.050 に答える