代码之家  ›  专栏  ›  技术社区  ›  Daniel Wood

UIRemoteNotificationType转换无效

  •  5
  • Daniel Wood  · 技术社区  · 16 年前

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

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

    但我收到以下错误:

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

    如果我只使用其中一种通知类型,它就可以工作,但是每次尝试使用多个通知类型时都会失败。知道我做错了什么吗?

    3 回复  |  直到 16 年前
        1
  •  14
  •   kennytm    16 年前

    您可能正在使用Objective-C++,这是从 int

    [… registerForRemoteNotificationTypes:
         (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert | …)];
    
        2
  •  4
  •   Laurent Etiemble    16 年前

    必须将结果强制转换为UIRemoteNotificationType:

    (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)
    

    这样方法得到了它所期望的结果。

        3
  •  1
  •   Gaurav aka sparsh    12 年前

    用这个:这会解决你的问题。

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