如何解决ios发送本地通知
程序被杀的时候发送通知,有时有效,有时收不到,这是我的代码 我该怎么办?我尝试加入,不杀程序直接发送
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = [[ViewController alloc]init];
[self.window makeKeyAndVisible];
UNUserNotificationCenter * center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:UNAuthorizationoptionAlert | UNAuthorizationoptionBadge | UNAuthorizationoptionSound completionHandler:^(BOOL granted,NSError * _Nullable error) {
if (granted) {
}else{
}
}];
return YES;
}
- (void)applicationWillTerminate:(UIApplication *)application{
UNUserNotificationCenter * center = [UNUserNotificationCenter
currentNotificationCenter];
UNMutableNotificationContent * content = [[UNMutableNotificationContent alloc]init];
content.title = @"title";
content.subtitle = @"childTitle";
content.body = @"titleContent";
content.sound = [UNNotificationSound defaultSound];
content.sound = [UNNotificationSound soundNamed:@"Define_Sound"];
content.badge = @1;
NSTimeInterval time = [[NSDate dateWithTimeIntervalSinceNow:1] timeIntervalSinceNow];
UNTimeIntervalNotificationTrigger * trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:time repeats:NO];
Nsstring * noticeId = @"noticeId";
UNNotificationRequest * request = [UNNotificationRequest requestWithIdentifier:noticeId content:content trigger:trigger];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (error == nil) {
}
}];
}
会不会是线程问题?查阅了很多博客都没有相关的方案。但是我看到它可以在offScreen上实现,每次我都能收到
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。