2011-12-14 608 views
5

Cuando uso [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; para registrar notificaciones remotas push, se produce un error diciendo cannot initialize a parameter of type 'UIRemoteNotificationType' with an rvalue of type 'int', ¿alguien sabe por qué? gracias.no se puede inicializar un parámetro de tipo UIRemote NotificationType con un valor rvalue de tipo int

entorno de mi proyecto: Xcode 4.2 + iOS 5.

+0

duplicado Posible http://stackoverflow.com/questions/2584453/uiremotenotificationtype-invalid-conversion – jbat100

+0

Estoy muy feliz y también gracias. –

Respuesta

14

Usted debe emitir explícitamente a UIRemoteNotificationType

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

¡Eso es todo! Muchas gracias. –

+0

@ jbat100 ¡Gracias! Me funcionó, pero ¿pueden explicarme por qué necesitamos un casting aquí? – Developer

+0

@Harsh Diría que el motivo es que una vez que realiza una operación bit a bit en la enumeración, por ejemplo, (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound), el resultado de la operación es el tipo que el compilador usa para representar la enumeración (que depende del rango de sus valores), generalmente un tipo entero. No estoy seguro de por qué no lo devuelve felizmente implícitamente a UIRemoteNotificationType en este caso. – jbat100

Cuestiones relacionadas