2

アラーム時間を1時間に設定しました。アプリケーションが実行モードにある場合、アラームは正常に動作しますが、バックグラウンドにある場合、アラームは正しく動作しません。バックグラウンドでアラームを実行するにはどうすればよいですか。

4

2 に答える 2

2

ローカル通知を使用する必要があります。とても簡単です。詳細については、このドキュメントを参照してください (プッシュ通知はリモート ソースから送信されるため、無視してかまいません)。

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008194-CH1-SW1

于 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 に答える