【问题标题】:ios local notification check before fireios 本地通知在火灾前检查
【发布时间】:2013-05-10 06:56:44
【问题描述】:

我正在尝试在应用未运行时每 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,然后播放声音并在上面放上徽章。

怎么做?

【问题讨论】:

    标签: ios xcode notifications uilocalnotification


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-21
      • 1970-01-01
      • 2018-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多