this following step i do in my app
in my appdelegate
#import <UserNotifications/UserNotifications.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = (id)self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound)
completionHandler:^(BOOL granted, NSError * _Nullable error) {
// Enable or disable features based on authorization.
}];
return YES;
}
and in my viewcontroller the code for generate local notification
-(IBAction)btnclicked:(id)sender
{
UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init];
content.title = @"gg";
content.subtitle = @"ggg";
content.body = @"hhh";
content.sound = [UNNotificationSound defaultSound];
// Deliver the notification in five seconds.
UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger
triggerWithTimeInterval:5 repeats:NO];
UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:@"2"
content:content trigger:trigger
];
// Schedule the notification.
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
NSLog(@"hii");
}];
}
Now When my app in foreground Notification not generating.
in ios 9 i use
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.soundName = @"Default";
localNotification.alertBody = @"my notification;)";
localNotification.fireDate = [NSDate date];
localNotification.category = @"Email";
localNotification.repeatInterval = kCFCalendarUnitDay;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
this code work in ios 9 but in ios 10 UILocalNotification is deprecate.
so how to generate local notification in ios 10 when your app in foreground ?