Reputation: 81
If I wanted to send a push notification after my app wasn't opened in a week saying to come back and play, do I need to get the user's permission to send them this local push notification?
Upvotes: 0
Views: 661
Reputation: 1206
Yes you need to register for local notification in iOS 8 only.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}
}
Upvotes: 0
Reputation: 933
For this you need to use Local notification. What you need to do is schedule a local notification after a week once user open the application. Everytime you schedule a notification cancel all earlier notification.
To cancel all notification use :
[[UIApplication sharedApplication] cancelAllLocalNotifications];
To schedule a notification use :
UILocalNotification* n1 = [[UILocalNotification alloc] init];
n1.fireDate = [NSDate dateWithTimeIntervalSinceNow: 60];
n1.alertBody = @"one";
UILocalNotification* n2 = [[UILocalNotification alloc] init];
n2.fireDate = [NSDate dateWithTimeIntervalSinceNow: 90];
n2.alertBody = @"two";
[[UIApplication sharedApplication] scheduleLocalNotification: n1];
[[UIApplication sharedApplication] scheduleLocalNotification: n2];
Upvotes: 1
Reputation: 4016
In iOS 8, you need to ask the user permission to schedule the Local Notification. It's not required before iOS 8.
One more thing, you have to know the difference between Push Notification and Local Notification. It will confuse people when you describe your problem. Push Notification is sent from the APNs server. And local notification is scheduled from you applications.
Upvotes: 1