Reputation: 292
I want to show a banner notification on the lock screen. But, while the screen is locked and off, it will not turn back on to show me the notifications.
The behavior I'm looking for is as follows:
The screen will be off, and locked. When the app gets a notification, it will turn on the screen and display a banner on the lock screen.
How can I do this?
Upvotes: 1
Views: 1991
Reputation: 830
This is automatically handled by iOS. When a notification is sent to an app, it will display the banner notification as you are looking for. In app delegate you can register notifications and handle.
UILocalNotification *notification = [[UILocalNotification alloc] init];
NSDate *fireDate = [[NSDate alloc] initWithTimeInterval:5 sinceDate:[NSDate date]];
[notification setFireDate:fireDate];
[notification setSoundName:UILocalNotificationDefaultSoundName];
NSTimeZone *timeZone = [NSTimeZone localTimeZone];
[notification setTimeZone:timeZone];
[notification setAlertBody:@"You have a new notification!"];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
This will create a new notification and fire it after 5 seconds. If the application is in the foreground, nothing will happen (unless handled in the app delegate). But if you background the application (such as shutting off the screen), you will receive a banner notification and hear the default notification sound.
Upvotes: 1
Reputation: 2503
If you need local notification : it means at specific time, the notification will be shown. Use UILocalNotification
If you need notification is sent from server. Here is what you need http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
Upvotes: 0