ALL BUSINESS
COMIDA
DIRECTORIES
EDUCATIONAL
ENTERTAINMENT
FASHION TIPS
FINER THINGS
FREE CREATOR TOOLS
HEALTH
MARKETPLACE
MEMBER's ONLY
MONEY MATTER$
MOTIVATIONAL
NEWS & WEATHER
TECHNOLOGIA
TELEVISION NETWORKS
USA VOTES 2024
VIDEOS
INVESTOR RELATIONS
IN DEVELOPMENT
Posted by - Latinos MediaSyndication -
on - March 7, 2023 -
Filed in - Technology -
-
285 Views - 0 Comments - 0 Likes - 0 Reviews
I am trying to trigger local notification for iOS with ObjectiveC. I can't use Swift as the react native's new architecture does not support it.
In my AppDelegate.m file I have added following code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; UNAuthorizationOptions options = UNAuthorizationOptionAlert + UNAuthorizationOptionSound; [center requestAuthorizationWithOptions:options completionHandler:^(BOOL granted, NSError * _Nullable error) { if (!granted) { NSLog(@"Something went wrong"); } }]; [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) { if (settings.authorizationStatus != UNAuthorizationStatusAuthorized) { // Notifications not allowed } }]; return YES; }
And in my button's action I am calling below code
- (IBAction)clickMe:(id)sender { UNMutableNotificationContent *content = [UNMutableNotificationContent new]; content.title = @"Don't forget"; content.body = @"Buy some milk"; content.sound = [UNNotificationSound defaultSound]; UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats:NO]; NSString *identifier = @"UYLLocalNotification"; UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger]; UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { if (error != nil) { NSLog(@"Something went wrong: %@",error); } }]; }
I want to trigger notification as soon as the button is pressed