Multiple UNUserNotifications not firing
Give a different "requestWithIdentifier" and "time delay" for each notification and try, may it works for you.
Local notifications are not firing in ios10
Set NSDateComponents like:
NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond|NSCalendarUnitTimeZone fromDate:[[NSDate date] dateByAddingTimeInterval:10]];
UNUserNotification doesn't fire out my local notification under iOS 12
Your code is working fine. I guess the problem is that your app is active when you receive the notifications. iOS
shows system notifications only if the app is not active. If app is active when notifications fires, the system triggers the UNUserNotificationCenterDelegate
method so you could handle the notification by yourself.
So since you set a notification time with a delay for 10
seconds, you need to run your app, then close it and wait for 10
seconds. Notification should appear if you give your app such a permission.
Showing a UIAlertAction based on UNUserNotification iOS not working as expected
I figured out how to do it.
I got rid of trying to implement the UNUserNotificationCenterDelegate
in another class and just did it in my View Controller:
#import <UIKit/UIKit.h>
#import "PickerViewHelperViewController.h"
@import UserNotifications;
@interface ViewController : UIViewController <UNUserNotificationCenterDelegate>
@property (weak, nonatomic) IBOutlet UIPickerView *pickerView;
@property (strong, nonatomic) PickerViewHelperViewController *pvHelper;
// Two methods needed to implement from the UNUserNotificationCenterDelegate
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler;
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)())completionHandler;
@end
and then just had the accompanying code within my .m file to present a local notification.
- (void) sendMessage:(UIApplication *)application title:(NSString *)title message:(NSString *)message{
UIAlertController *ac = [UIAlertController alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"Go Away!" style:UIAlertActionStyleDefault handler:nil];
[ac addAction:action];
dispatch_async(dispatch_get_main_queue(), ^{
[application.keyWindow.rootViewController presentViewController:ac animated:YES completion:^{
application.applicationIconBadgeNumber = 0;
}];
});
}
//Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
NSLog(@"User Info : %@",notification.request.content.userInfo);
[self sendMessage:[UIApplication sharedApplication] title:@"local notification within App" message:notification.request.content.body];
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionBadge);
}
//Called when a notification is delivered to a background app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void(^)())completionHandler{
NSLog(@"User Info : %@",response.notification.request.content.userInfo);
[self sendMessage:[UIApplication sharedApplication]
title:@"I habe been opened from outside the App"
message:response.notification.request.content.body];
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}
my create notification and ask for permission methods above remained unchanged in the code.
This allowed for a local notification to appear within the app and for a notification to appear if the app was opened via the notification.
Related Topics
Fontawesome Pro and Xamarin.iOS Only One Font Can Be Active
Can the -Objc Flag Be Applied Selectively to Static Libraries
Avaudiosession .Defaulttospeaker Changes Mic Input
How to Get Touchid Information and Compare to a Fingerprint Database
Done Button Event Mpmovieplayercontroller
How to Create Back Button in Navigation Bar
Constraints for Centering One Button When the Other Is Hidden
Audiokit iOS Aksamplermetronome
How to Crop a Uiimage in Swift
Gamecenter iOS 9 Gamecenter Gklocalplayerlistener Methods Not Called
Does iOS Calendar Support a Url Scheme
Check If Username Already Exist'S:Swift, Firebase
Firebase Queryorderedbychild() Method Not Giving Sorted Data
Creating an Image Format with an Unknown Type Is an Error Objective-C Xcode 8