今夜遅くまでこのコードを適切にテストすることはできませんが、事前に間違いを避けるために、これを使用して通知をオンまたはオフにすることはできますか? これNSUserDefault
は switch ステートメントからのものであり、一目瞭然です。登録と登録解除は、iOS 設定のプッシュ通知スイッチの機能 (通知のオンとオフ) を模倣していますか?
-(void)notification{
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"Switch"]) {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"Switch"]) {
[[UIApplication sharedApplication]unregisterForRemoteNotifications];
}
}