小编Nou*_*991的帖子

iOs 8,在后台开始播放声音,闹钟应用程序

我知道SOF有很多问题,但这是"最新的"问题.问题是,我正在尝试创建和报警应用程序,我知道有一个事实,那里有完美(不知何故)工作的警报应用程序,即使应用程序没有运行,并在后台.

我的问题是:你的应用程序已经在后台如何开始播放声音?

UILocalNotification非常棒,但只有application:(_:didReceiveLocalNotification:)在用户点击了您的通知后才能获得,因此使用AVAudioPlayer播放声音不起作用,我想播放声音,无论用户点击它还是没有.当然已经Required background modes: App plays audio or streams audio/video using AirPlayinfo.plist已经设定.一旦音乐开始播放,即使我去了背景,它也会继续播放.

我不想使用UILocalNotificaation声音,因为它限制在30秒内,只能播放与应用程序捆绑在一起的声音.

任何见解?想法?

示例代码:

    var notif = UILocalNotification()
    notif.fireDate = self.datePicker.date
    notif.alertBody = "test"
    UIApplication.sharedApplication().scheduleLocalNotification(notif)
Run Code Online (Sandbox Code Playgroud)

当用户选择并报警并单击保存时,将调用上面的代码.

以下是AppDelegate中发生的事情:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
    NSLog("launched")
    application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert |
        UIUserNotificationType.Badge, categories: nil
        ))
    AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
    AVAudioSession.sharedInstance().setActive(true, error: nil)

    self.sound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("sound", ofType: "caf"))
    self.audioPlayer = AVAudioPlayer(contentsOfURL: sound, error: nil)

    return true
}

func application(application: UIApplication!, …
Run Code Online (Sandbox Code Playgroud)

audio alarm ios swift

13
推荐指数
1
解决办法
9899
查看次数

如何支持iOs 9功能,同时保持iOs 8的支持?

基本上问题在于标题.我确信有一种方法可以将您的应用程序发送到早期版本的iO(在本例中为8),同时仍然可以使用较新操作系统版本的独有功能.示例:我的应用程序至少支持iOs 8.3,并且对于最新版本的iOs 9,我想添加对强制触摸的支持(仅在iOs 9中可用),但同时,我希望能够修复错误并进行UI改进,并将更新发送到两个版本.主要的应用程序这样做,例如fb,所以必须有一种方式,但我找不到任何地方,我放弃了:(

编辑:有一个简洁的方法吗?没有检查respondsToSelector和这些东西?像单独的项目?或者也许xcconfig文件可以做到这一点?我只是想知道..因为if else当你谈论企业/大型应用时,拥有每个ios 9目标功能并不是一个很好的解决方案

iphone ios ios8 ios9

3
推荐指数
1
解决办法
802
查看次数

标签 统计

ios ×2

alarm ×1

audio ×1

ios8 ×1

ios9 ×1

iphone ×1

swift ×1