- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if (userInfo) {
NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"Info" message: message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
[self.window.rootViewController presentViewController:alert animated:YES completion:nil];
}
}
출처 : https://stackoverflow.com/questions/39263079/apns-payload-message-json-format-directly-shown
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.title = @"Title";
content.body = @"Body";
content.sound = [UNNotificationSound defaultSound];
NSURL *imageURL = [NSURL URLWithString:@"file:/some/path/in/app/image.png"];
NSError *error;
UNNotificationAttachment *icon = [UNNotificationAttachment attachmentWithIdentifier:@"image" URL:imageURL options:nil error:&error];
if (error)
{
NSLog(@"error while storing image attachment in notification: %@", error);
}
if (icon)
{
content.attachments = @[icon];
}
출처 : https://stackoverflow.com/questions/37839171/how-to-display-image-in-ios-push-notification
if #available(iOS 10.0, *) {
UNMutableNotificationContent *objNotificationContent = [[UNMutableNotificationContent alloc] init];
objNotificationContent.body = @"Notifications";
objNotificationContent.badge = @([[UIApplication sharedApplication] applicationIconBadgeNumber] + 1);
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:60 repeats:NO];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"identifier" content:objNotificationContent trigger:trigger];
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (!error) {
}
else {
}
}];
}
else
{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = [[NSDate date] dateByAddingTimeIntervalInterval:60];
localNotif.alertBody = @"Notifications";
localNotif.repeatInterval = NSCalendarUnitMinute;
localNotif.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
출처 : https://stackoverflow.com/questions/42363610/uilocalnotification-in-ios-9-and-unmutablenotificationcontent-in-ios-10