[英]How can I show a custom Local notification View or an Custom Alert view when app is in Background?
Actually I want to show a local notification in my app. 其实我想在我的应用程序中显示本地通知。 But i want to show this notification with some custom design like ok and cancel button on it.And on the click of Ok and Cancel i want to perform some actions.Please suggest something.
但我想通过一些自定义设计显示此通知,如ok和取消按钮。点击确定和取消我想要执行一些操作。请提出建议。
Thanks In advance. 提前致谢。
i am impliment this code for custom local notification may be helping you where Accept is identifier where you get in delegates of local notification in appDelegate.m 我很自豪这个自定义本地通知代码可能会帮助你在哪里接受是appDelegate.m中本地通知代表的标识符
NSString *idetnt = @"Accept";
NSString *idetnt1 = @"Reject";
NSString *idetnt2 = @"Local Notification";
UIMutableUserNotificationAction *notificationAction1 = [[UIMutableUserNotificationAction alloc] init];
notificationAction1.identifier = idetnt;
notificationAction1.title = @"Snooze";
notificationAction1.activationMode = UIUserNotificationActivationModeBackground;
notificationAction1.destructive = NO;
notificationAction1.authenticationRequired = NO;
UIMutableUserNotificationAction *notificationAction2 = [[UIMutableUserNotificationAction alloc] init];
notificationAction2.identifier = idetnt1;
notificationAction2.title = @"Call";
notificationAction2.activationMode = UIUserNotificationActivationModeBackground;
notificationAction2.destructive = YES;
notificationAction2.authenticationRequired = YES;
UIMutableUserNotificationAction *notificationAction3 = [[UIMutableUserNotificationAction alloc] init];
notificationAction3.identifier = @"Reply";
notificationAction3.title = @"Reply";
notificationAction3.activationMode = UIUserNotificationActivationModeForeground;
notificationAction3.destructive = NO;
notificationAction3.authenticationRequired = YES;
UIMutableUserNotificationCategory *notificationCategory = [[UIMutableUserNotificationCategory alloc] init];
notificationCategory.identifier = @"Email";
[notificationCategory setActions:@[notificationAction1,notificationAction2,notificationAction3] forContext:UIUserNotificationActionContextDefault];
[notificationCategory setActions:@[notificationAction1,notificationAction2] forContext:UIUserNotificationActionContextMinimal];
NSSet *categories = [NSSet setWithObjects:notificationCategory, nil];
UIUserNotificationType notificationType = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:notificationType categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:600];
localNotification.alertBody = idetnt2;
localNotification.category = @"Email";
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
when ur app in background then this methods call 当你的应用程序在后台然后这个方法调用
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler
{
if ([identifier isEqualToString:@"Accept"])
{
}
else if ([identifier isEqualToString:@"Reject"])
{
}
else if ([identifier isEqualToString:@"Reply"])
{
}
if(completionHandler != nil)
completionHandler();
}
when ur app in foreground then this methods call 当你的应用程序在前台然后这个方法调用
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)localNotification
{
}
Go to capability option and click on remote notification 转到功能选项,然后单击远程通知
您无法添加完全自定义,但您的通知可以设置category
属性以指定应使用哪些通知设置,并且这些通知设置可以指定要显示的按钮以及用户选择这些按钮时的按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.