UIRemoteNotificationType无效转换

Dan*_*ood 5 iphone cocoa-touch

我试图在我的应用程序中使用这个相当标准的代码行:

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
Run Code Online (Sandbox Code Playgroud)

但是我收到了以下错误:

error: invalid conversion from 'int' to 'UIRemoteNotificationType'
Run Code Online (Sandbox Code Playgroud)

如果我只使用其中一种通知类型,但每次尝试使用多个通知类型时都会失败.我有什么想法我做错了吗?

ken*_*ytm 14

您可能正在使用Objective-C++,int不允许从枚举转换为枚举.

尝试添加显式强制转换:

[… registerForRemoteNotificationTypes:
     (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert | …)];
Run Code Online (Sandbox Code Playgroud)