に次のコードがありますViewController.m
。
-(void) checker {
UILocalNotification *notification = [[UILocalNotification alloc] init];
[notification setAlertBody: @"Im your local notification"];
[notification setFireDate: [NSDate dateWithTimeIntervalSinceNow: 1]];
[notification setTimeZone: [NSTimeZone defaultTimeZone]];
[UIApplication setScheduledLocalNotifications: [NSArray arrayWithObject: notification]];
}
最後の行で警告が生成されます。
クラス メソッド '+setScheduledLocalNotifications' が見つかりません (戻り型のデフォルトは id です)
処理中にエラーが発生します。通知をインスタンス化するにはどうすればよいですか? 私が言ったように、私は新しいので、完全な回答を提供していただければ幸いです。
編集: 60 秒ごとに繰り返され、通知を送信する関数を呼び出すタイマーがあります。
timer = [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(checker) userInfo:nil repeats:YES];
/* ... */
-(void)checker {
NSLog(@"Notification routine");
UIApplication* app = [UIApplication sharedApplication];
NSArray *oldNotifications = [app scheduledLocalNotifications];
// Clear out the old notification before scheduling a new one.(if needed)
if ([oldNotifications count] > 0)
[app cancelAllLocalNotifications];
// Create a new notification.
UILocalNotification* alarm = [[[UILocalNotification alloc] init] autorelease];
if (alarm) {
alarm.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
alarm.timeZone = [NSTimeZone defaultTimeZone];
alarm.repeatInterval = 0;
alarm.alertBody = @"Msg to show";
[app scheduleLocalNotification:alarm];
}
}
ログは 1 分間に 1 回しか発火していませんが、oldNotifications
カウントは増加しません。