static int hasLocalNotifications = 0; //0-undefined 1-YES 2-NO
+(BOOL)hasLocalNotifications{
if (hasLocalNotifications==0) {
Class myClass = objc_getClass("UILocalNotification");
if(myClass==0){
hasLocalNotifications=2; //NO support for UILocalNotification
return FALSE;
}else {
hasLocalNotifications=1; //There is support for UILocalNotification
return TRUE;
}
}
if(hasLocalNotifications==1)
return YES;
else
return NO;
}
Managing notifications
I think that UILocalNotiications are essentially easy to manage. The problem is when you have to remove or change one existing notification.
You can access the list of your application notifications through the function
NSArray* localNotificationsList=[application scheduledLocalNotifications];. Initially I identified my notifications comparing fireDate and the body. But there is an easiest way using userInfo. You can store an ID linked with your information in the database in this property.You still have to go over all the notifications, but I think this way you can find your unique notification even having two with the same date and body.
//search the local notification using the ID
for(id localNotification in localNotificationsList){
NSNumber *id = [ [localNotification userInfo] objectForKey:@"ID"];
if ([id longLongValue]==self.ID ) {
[application cancelLocalNotification:localNotification];
return;
}
}
A final clarification, I use as ID a long long int, because it is the key in the database of the associated element.
Hi!, I am Eduado Oliveros, if you want to contact me, send an email to eduardo.oliveros(at)gmail dot com
0 comentarios:
Publicar un comentario en la entrada