2010-04-06 6 views
5

Je suis en train d'utiliser cette ligne assez standard de code dans mon application:UIRemoteNotificationType conversion invalide

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

Mais je reçois l'erreur suivante:

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

Il fonctionne si j'utilise un seul des types de notification, mais échoue à chaque fois si j'essaie d'en utiliser plus d'un. Des idées de ce que je fais mal?

Répondre

14

Vous utilisez probablement Objective-C++, cette conversion implicite de int en une énumération n'est pas autorisée.

Essayez d'ajouter un casting explicite:

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

Vous avez jeter le résultat comme UIRemoteNotificationType:

(UIRemoteNotificationType)(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound) 

De cette façon, la méthode a obtenu ce qu'il attend.

+0

C'était correct mais j'ai accepté la réponse de KennyTM car elle fournissait le détail pourquoi. Merci. –

1

Utilisez ceci: Cela permettra de résoudre ur problème.

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