Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS "Local" Push Notification [closed]

Hey,

I'm looking for a way to make "local" push notifications. I can't figure out how I should do this, so I'm looking for some help. What I need is:

  • a way to send a notification for a user who haven't opened the application within 24 hours. (Or that an int havent change)

I really hope that one of you got time to help me, thanks!

like image 974
Mathias Mønsted Avatar asked Jun 27 '13 09:06

Mathias Mønsted


People also ask

Do local notifications work when app is closed?

The local notification should occur at the schedule time even if the app is closed.

Can you send local notifications while app is in background?

Notifications could be created at any moment (on Foreground, Background or even when the application is terminated/killed).

Why push notification is not working for IOS?

You can fix an iPhone that's not getting notifications by restarting it or making sure notifications are turned on. You should also make sure your iPhone is connected to the internet so apps can receive notifications. If all else fails, you should try resetting the iPhone — just make sure to back it up first.


1 Answers

This is pretty straight forward:

1) When the app is closed, schedule a local notification that will fire in 24 hours

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    UILocalNotification *notification = [[UILocalNotification alloc] init];
    notification.fireDate = [[NSDate date] dateByAddingTimeInterval:60*60*24];
    notification.alertBody = @"24 hours passed since last visit :(";
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];
}

2) if the app is opened (before the local notification fires), cancel the local notification

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
}
like image 63
tilo Avatar answered Oct 03 '22 11:10

tilo