Acabo de descargar xcode y trato de hacer un ejemplo de notificación local. La pregunta es si la notificación local funciona en el simulador.notificación local de iphone en el simulador
agradecimiento
Acabo de descargar xcode y trato de hacer un ejemplo de notificación local. La pregunta es si la notificación local funciona en el simulador.notificación local de iphone en el simulador
agradecimiento
notificaciones locales trabajan en el simulador, notificaciones push No
trabajo Notificación Sí Local de notificación local. Click here para apple doc.
Sí, las notificaciones locales funcionan con el simulador. Sin embargo, asegúrese de que esté implementando aplicación: didreceiveLocalNotification en delegado de la aplicación si desea ver el nofication mientras que su aplicación está en primer plano:
- (void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"MyAlertView"
message:notification.alertBody
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
if (alertView) {
[alertView release];
}
}
De lo contrario, asegúrese de programar su notificación por algún tiempo en el futuro , a continuación, cierre la aplicación , con el fin de ver el trabajo de la muestra de Apple:
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil) return;
NSDate *fireTime = [[NSDate date] addTimeInterval:10]; // adds 10 secs
localNotif.fireDate = fireTime;
localNotif.alertBody = @"Alert!";
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
es fácil pensar que no va a implementar el código de prueba correctamente, y simplemente no están manejando el evento mientras que la aplicación Esta corriendo.
Para probar las notificaciones locales en simulador de iPhone, siga estos pasos:
Estos pasos me ayudaron siempre a obtener notificaciones locales exitosas.
Otro problema que puede encontrar, para cualquiera que tropiece con esta pregunta anterior: iOS 8 introdujo nuevos permisos de notificación; y su aplicación tiene que solicitarlos explícitamente.
En su AppDeligate.m
:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//register local notifications
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}
//the rest of your normal code
return YES;
}
Si no, la notificación nunca se disparará, y obtendrá un mensaje maravilloso como este en sus registros: "Attempting to schedule a local notification <UIConcreteLocalNotification: 0x7ae51b10>{... alert details ...} with an alert but haven't received permission from the user to display alerts
"
usted se enlaza está roto. – mtl