小编Spe*_*nak的帖子

如何每天重复UNUserNotification?

我正在尝试允许用户安排通知,以便在每天的特定时间打开应用.到目前为止,我已经能够通过计算从现在到用户选择的时间以及在X秒内安排通知的时间来安排第一个通知.但是,有没有办法让我可以设置每天重复的通知?如果您感到困惑,这是我的代码的一部分:

let newTime: Double = Double(totalDifference)
let notifTrigger = UNTimeIntervalNotificationTrigger(timeInterval: newTime, repeats: false)
let request = UNNotificationRequest(identifier: "openApp", content: notif, trigger: notifTrigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: { error in
    if error != nil {
        print(error!)
        completion(false)
    } else {
        completion(true)
    }
})
Run Code Online (Sandbox Code Playgroud)

任何帮助深表感谢

ios swift ios10 unusernotificationcenter

2
推荐指数
1
解决办法
2233
查看次数

Swift 3 - 尝试执行获取请求时程序崩溃

目前,我正在尝试在我的一个视图控制器上获取歌曲类型的实体。这是相关的代码,我有:

import CoreData

class TimerScreenVC: UIViewController, NSFetchedResultsControllerDelegate {

var songController: NSFetchedResultsController<Song>!


override function viewDidLoad() {
   super.viewdidLoad()
   attemptSongFetch()
}


func attemptSongFetch() {
    let fetchRequest: NSFetchRequest<Song> = Song.fetchRequest()
    let controller = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
    let sortByTitle = NSSortDescriptor(key: "title", ascending: true)
    fetchRequest.sortDescriptors = [sortByTitle]
    songController = controller
    do {
        try songController.performFetch()
    } catch {
        let error = error as NSError
        print("\(error)")
    }


}


    func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
    print("called will change")
}
    func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) { …
Run Code Online (Sandbox Code Playgroud)

xcode ios swift swift3 ios10

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

有没有办法创建一个我可以改变的自定义类?

目前,我已经制作了一个名为SongNames的自定义类.这是它的代码:

import Foundation

class songAttributes {
private var _songTitle: String!
private var _songURL: String!

var songTitle: String {
    return _songTitle
}

init(songTitle: String, songURL: String) {
    _songURL = songURL
    _songTitle = songTitle

}
var songURL: String {
    return _songURL
}

}
Run Code Online (Sandbox Code Playgroud)

我没有问题为这个类设置值.例如,我可能会写:

var songAttribute = songAttributes(songTitle: "That's What I Like", url: "some url")
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试更改我刚刚创建的变量的属性,比如说:

songAttribute.songTitle = "Locked Out of Heaven"
Run Code Online (Sandbox Code Playgroud)

我收到消息:"错误:songTitle是一个获得唯一的属性"

话虽如此,有没有办法搞砸我的SongName类,以便可以更改这些属性,而不仅仅是get-only?

properties ios swift

-1
推荐指数
1
解决办法
75
查看次数