2012-08-07 10 views
6

Sé que esta pregunta se ha hecho muchas veces en StackOverflow pero no pude configurar la alarma en mi aplicación porque soy muy nuevo en iOS? Estoy siguiendo este tutorial para configurar una alarma:¿Cómo configurar una alarma en iOS?

Setting a reminder using UILocalNotification in iOS.

Sin embargo, no parece estar funcionando para mí.

Estoy en necesidad de configurar la alarma diariamente digamos 5.00 PM diariamente. No puedo usar el selector de fecha para elegir la hora.

Respuesta

9
  1. Primero en su xib, (o código) ajustar el modo de selección de fecha: tiempo (por defecto es la fecha & tiempo)

  2. el sistema asume que el firedate es la fecha actual, y el tiempo es el tiempo que el usuario ha elegido. Esto no es un problema porque establece un intervalo de repetición para que funcione. Lo he probado

    UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
    [localNotif setFireDate:datePicker.date]; 
    [localNotif setRepeatInterval:NSDayCalendarUnit]; 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 
    

PD: Sería una buena idea para ajustar los segundos a 0 usando NSDateComponents clase con el fin de ajustar la alarma para que suene en el primer segundo de la hora que desee. Puede comprobar el:

Local notifications in iOS.

tutorial se publicó, el de cómo hacer esto.

+0

Gracias por tu respuesta, pero logré hacerlo de otro modo ... Funciona. Una pregunta ... ¿Es posible abrir la vista de notificación personalizada en lugar de la predeterminada y también me gustaría agregar un sonido personalizado que se agregó en mi proyecto si es posible ... +1 para su compatibilidad – GoCrazy

+2

No puede mostrar una ventana emergente de notificación personalizada. Puede agregar un sonido personalizado, pero debe estar en el paquete de la aplicación. Por lo tanto, es imposible reproducir un sonido que la aplicación haya descargado de Internet. Solo puede reproducir sonidos del sistema o sonidos que haya importado a su aplicación antes de la compilación. De nada. Acepte la respuesta si cree que es correcta, para ayudar a los futuros usuarios a encontrar la solución a este problema. –

+0

sí. eso es lo que estoy buscando ¿podría usted poder publicar algunos códigos para reproducir el sonido en el paquete de la aplicación que importó antes de la compilación, por favor – GoCrazy

0

Es posible que tenga que cambiar el estilo del selector de fecha para permitir cambiar el tiempo además de solo la fecha.

+0

Gracias por sus answer..Is posible publicar ningún tutorial para configurar la alarma – GoCrazy

+1

El tutorial original espera que ya tenga experiencia en este entorno, y por una buena razón: en cualquier tutorial en ese nivel o más avanzado, hay muchas cosas básicas con las que puede tropezar. Le sugiero que repase los aspectos básicos y vaya subiendo hasta este tipo de tareas; de lo contrario, no podrá hacer nada, cambiarlo a su gusto o arreglarlo si se rompe. – Jesper

+0

Gracias por su comentario ... en realidad la alarma se notificó pero no pude obtener la ventana emergente ... ¿cuál será el problema? – GoCrazy

1
+ (void)addLocalNotification:(int)year:(int)month:(int)day:(int)hours:(int)minutes:(int)seconds:(NSString*)alertSoundName:(NSString*)alertBody:(NSString*)actionButtonTitle:(NSString*)notificationID 

llamar a este método con los parámetros y el uso de este

+ (void)addLocalNotification:(int)year:(int)month:(int)day:(int)hours:(int)minutes:(int)seconds:(NSString*)alertSoundName:(NSString*)alertBody:(NSString*)actionButtonTitle:(NSString*)notificationID { 
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; 

//set the notification date/time 
NSDateComponents *dateComps = [[NSDateComponents alloc] init]; 
[dateComps setDay:day]; 

[dateComps setMonth:month]; 

[dateComps setYear:year]; 
[dateComps setHour:hours]; 

[dateComps setMinute:minutes]; 
[dateComps setSecond:seconds]; 

NSDate *notificationDate = [calendar dateFromComponents:dateComps]; 
[dateComps release]; 

UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
if (localNotif == nil) 
    return; 
localNotif.fireDate = notificationDate; 
localNotif.timeZone = [NSTimeZone defaultTimeZone]; 

// Set notification message 
localNotif.alertBody = alertBody; 
// Title for the action button 
localNotif.alertAction = actionButtonTitle; 

localNotif.soundName = (alertSoundName == nil) ? UILocalNotificationDefaultSoundName : alertSoundName; 

//use custom sound name or default one - look here to find out more: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html%23//apple_ref/doc/uid/TP40008194-CH103-SW13 

localNotif.applicationIconBadgeNumber += 1; //increases the icon badge number 

// Custom data - we're using them to identify the notification. comes in handy, in case we want to delete a specific one later 
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:notificationID forKey:notificationID]; 
localNotif.userInfo = infoDict; 

// Schedule the notification 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 
[localNotif release]; 
} 
0

puede probar esta

UILocalNotification *todolistLocalNotification=[[UILocalNotification alloc]init]; 
[todolistLocalNotification setFireDate:[lodatepicker date]]; 
[todolistLocalNotification setAlertAction:@"Note list"]; 
[todolistLocalNotification setTimeZone:[NSTimeZone defaultTimeZone]]; 
[todolistLocalNotification setAlertBody:text_todolist]; 
[todolistLocalNotification setHasAction:YES]; 
Cuestiones relacionadas