我有这段代码可以在iOS7中运行。它让我能够关闭声音,警报和徽章。如果showMessage,showBadge or show sound
设置为零,则也会关闭相应的UIremote类型。正如你们许多人所知,iOS8远程通知已经改变。有人可以指导我如何在iOS 8上完成这项工作吗?
UIRemoteNotificationType notificationType = UIRemoteNotificationTypeNone;
if (showMessage == 1 )
notificationType |= UIRemoteNotificationTypeAlert;
if (showBadge == 1 )
notificationType |= UIRemoteNotificationTypeBadge;
if (showSound == 1 )
notificationType |= UIRemoteNotificationTypeSound;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationType];
这是我尝试过的,但是我收到错误No visible @interface'UIApplication'声明选择器'registerForUserNotificationSettings:'
UIUserNotificationType userNotificationType = UIUserNotificationTypeNone;
if (showMessage == 1 )
userNotificationType |= UIUserNotificationTypeAlert;
if (showBadge == 1 )
userNotificationType |= UIUserNotificationTypeBadge;
if (showSound == 1 )
userNotificationType |= UIUserNotificationTypeSound;
[[UIApplication sharedApplication] registerForUserNotificationSettings:userNotificationType];
答案 0 :(得分:-1)
在您的代码中,您传递了UIUserNotificationType对象,但您需要传递UIUserNotificationSettings对象。
UIUserNotificationType notificarionType = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:notificarionType categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];