イベントの日付が近づくと、通知センターを介してユーザーにアラートを送信するアプリを作成しています。しかし、日付ピッカーで日付を設定してアプリを閉じると、通知が表示されません。プロビジョニング プロファイルでプッシュ通知を有効にしました。objectForKey 領域が原因である可能性があります。ImportantDatesViewController_iPhone1 と ImportantDatesViewController_iPad1 という名前の 2 つのペン先 (iPhone 用と iPad 用) があります。「ImportantDatesViewController」だけでなく、objectForKey 領域を nib 名に変更する必要がありますか? また、私の .h および .m ファイル名は、単に ImportantDatesViewController でもあります。申し訳ありませんが、私はまだこれに非常に慣れておらず、学習を続けています。通知センターを処理する私のプロジェクトのすべてのコードは次のとおりです。これは、ビュー コントローラーに配置したものです。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"mm'/'dd'/'yyyy"];
NSDate *eventDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"ImportantDatesViewController.selectedDate"];
localNotif.fireDate = [eventDate dateByAddingTimeInterval:-60*60*60];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = @"Event coming in three days!";
localNotif.alertAction = nil;
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
return YES;
}
また、下部の App Delegate の didFinishLaunchingWithOptions メソッドにこのコードを追加しました。これでうまくいくと思いました。
[[UIApplication sharedApplication]registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
どんな助けでも大歓迎です、ありがとう!