ios 火灾前本地通知检查

标签 ios xcode notifications uilocalnotification

当应用程序未运行时,我尝试每 n 分钟运行一些功能。 我认为本地通知适合于此,但我有一个问题。

如果我将本地通知设置为:

 -(void)notification{
     UILocalNotification *localNotif = [[UILocalNotification alloc] init];
     if (localNotif == nil)
         return;
     localNotif.fireDate = [[NSDate date] dateByAddingTimeInterval:15];
     //localNotif.timeZone = [NSTimeZone defaultTimeZone];

 // Notification details
     localNotif.alertBody = @"marko";
 // Set the action button
     localNotif.alertAction = @"View";

     localNotif.soundName = UILocalNotificationDefaultSoundName;
     localNotif.applicationIconBadgeNumber = 1;

 // Specify custom data for the notification
     NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
     localNotif.userInfo = infoDict;

// Schedule the notification
   [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}

每次都会触发通知,然后执行以下操作:

 - (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
NSLog(@"Recieved Notification %@",notif);
 }

我想要的是在 15 秒后首先触发一些函数,如果函数返回 YES,则播放声音并在其上放置角标(Badge)。

怎么做?

最佳答案

如果系统发送通知时应用程序位于最前面并且可见,则不会显示任何警报,不会标记任何图标,并且不会播放任何声音。但是,如果应用程序委托(delegate)实现了 application:didReceiveLocalNotification: ,则会调用它。

确保您正在设备中进行测试。

关于ios 火灾前本地通知检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16476809/

相关文章:

iphone - 使用json数据

xcode - 船舶与硬币相撞无法正常工作

android - 如何创建弹出通知,例如 whatsapp for android 中使用的通知?

ssl - 如何使用 ssl 在 Windows 8 和 WP8 应用程序之间进行通信?

ios - 定位 ARKIT 模型

ios - UIImage init with scale in swift 错误地说 "Extra Argument"

ios - 循环 ImageView 动画 iOS

iphone - 暂停本地通知

ios - 如何快速更改 Collection View 的高度

ios - OpenGL 2D 游戏纹理工件