2010-04-06 68 views
5

我试图用这个相当标准行代码在我的应用程序:UIRemoteNotificationType无效转换

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; 

,但我收到如下错误:

error: invalid conversion from 'int' to 'UIRemoteNotificationType' 

它的工作原理,如果我只用一个的通知类型,但每次都失败,如果我尝试使用多个。任何想法我做错了什么?

回答

14

您可能正在使用Objective-C++,其中隐式从int转换为枚举是不允许的。

尝试添加一个明确的转换:

[… registerForRemoteNotificationTypes: 
    (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert | …)]; 
4

你必须把结果作为UIRemoteNotificationType:

(UIRemoteNotificationType)(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound) 

这样的方法得到了它期待。

+0

这是正确的,但我接受KennyTM的答案,因为它提供了详细的原因。谢谢。 – 2010-04-06 12:36:21

1

使用此:这将解决乌尔问题。

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationType)(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];