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 (将#修改为@)