Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIRemoteNotificationType invalid conversion

I'm trying to use this fairly standard line of code in my app:

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

But am receiving the follow error:

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

It works if I only use one of the notification types but fails every time if I try and use more than one. Any ideas what I'm doing wrong?

like image 344
Daniel Wood Avatar asked Apr 06 '10 11:04

Daniel Wood


2 Answers

You're probably using Objective-C++, which implicit conversion from int to an enum is disallowed.

Try to add an explicit cast:

[… registerForRemoteNotificationTypes:
     (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert | …)];
like image 72
kennytm Avatar answered Sep 30 '22 17:09

kennytm


You have to cast the result as UIRemoteNotificationType:

(UIRemoteNotificationType)(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)

This way the method got what it is expecting.

like image 39
Laurent Etiemble Avatar answered Sep 30 '22 18:09

Laurent Etiemble