ios - 从 UIUserNotificationTypeNone 传递到 UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeBadge | UI用户通知类型声音

标签 ios objective-c xcode

您知道从 UIUserNotificationTypeNone 传递到 UIUserNotificationTypeAlert | 的方法吗? UIUserNotificationTypeBadge | UIUserNotificationTypeBadge | UIUserNotificationTypeSound(iOS8)?

传递给 UIUserNotificationTypeNone 效果很好,但当用户尝试再次切换以启用...

这是我的代码:

 // Register for Push Notifications, if running iOS 8
                    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)])
                    {
                        UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
                        UIUserNotificationSettings * settingsAvailable = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
                        [application registerUserNotificationSettings:settingsAvailable];
                        [application registerForRemoteNotifications];
                    }

                    else
                    {
                        // Register for Push Notifications before iOS 8
                        [application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
                    }

切换启用委托(delegate)“didRegisterUserNotificationSettings”方法后

// Register to receive notifications
[application registerForRemoteNotifications];

NSLog(@"The app is registered for the types: %@", notificationSettings);

返回:

The app is registered for the types: <UIUserNotificationSettings: 0x15e9e790; types: (none);>

提前致谢

最佳答案

这是因为系统设置中的通知设置已关闭。

关于ios - 从 UIUserNotificationTypeNone 传递到 UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeBadge | UI用户通知类型声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26261503/

相关文章:

ios - 在启动时在外部变量 xcode 中创建数组

c++ - Objective-C block 、C++ 变量和异步代码

ios - Mac OS X 构建服务器 IPA 中缺少 archived-expanded-entitlements.xcent 文件

xcode - ios 僵尸检测

ios - 如何检测电子邮件地址更改是否已还原?

iphone - 自定义 UITableViewCell 编辑AccessoryView?

ios - 如何从 iPad 的 native 应用程序在 Safari 中打开链接?

objective-c - NSOperationQueue 中多个 NSOperation 实例中的 NSUrlConnection

iphone - 在 Interface Builder 和 XCode 中连接 UILabel?

xcode - 从应用程序支持文件夹中删除文件后应用程序读取数据