在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):sindresorhus/LaunchAtLogin开源软件地址(OpenSource Url):https://github.com/sindresorhus/LaunchAtLogin开源编程语言(OpenSource Language):Swift 64.7%开源软件介绍(OpenSource Introduction):LaunchAtLogin
It's usually quite a convoluted and error-prone process to add this. No more! This package works with both sandboxed and non-sandboxed apps and it's App Store compatible and used in apps like Plash, Dato, Lungo, and Battery Indicator.
Sindre‘s open source work is supported by the community Special thanks to:Requirements
InstallSwift Package ManagerAdd CarthageWarning: Carthage is not recommended. Support for it will be removed at some point in the future.
UsageSwift Package ManagerAdd a new “Run Script Phase” below (not into) “Copy Bundle Resources” in “Build Phases” with the following: "${BUILT_PRODUCTS_DIR}/LaunchAtLogin_LaunchAtLogin.bundle/Contents/Resources/copy-helper-swiftpm.sh" (I would name the run script CarthageAdd a new “Run Script Phase” below (not into) “Embed Frameworks” in “Build Phases” with the following: "${PROJECT_DIR}/Carthage/Build/Mac/LaunchAtLogin.framework/Resources/copy-helper.sh" (I would name the run script Use it in your appNo need to store any state to UserDefaults. Note that the Mac App Store guidelines requires “launch at login” functionality to be enabled in response to a user action. This is usually solved by making it a preference that is disabled by default. Many apps also let the user activate it in a welcome screen. As static propertyimport LaunchAtLogin
print(LaunchAtLogin.isEnabled)
//=> false
LaunchAtLogin.isEnabled = true
print(LaunchAtLogin.isEnabled)
//=> true SwiftUIThis package comes with a struct ContentView: View {
var body: some View {
LaunchAtLogin.Toggle()
}
} The default label is struct ContentView: View {
var body: some View {
LaunchAtLogin.Toggle {
Text("Launch at login")
}
}
} Alternatively, you can use import SwiftUI
import LaunchAtLogin
struct ContentView: View {
@ObservedObject private var launchAtLogin = LaunchAtLogin.observable
var body: some View {
Toggle("Launch at login", isOn: $launchAtLogin.isEnabled)
}
} CombineJust subscribe to import Combine
import LaunchAtLogin
final class ViewModel {
private var isLaunchAtLoginEnabled = LaunchAtLogin.isEnabled
private var cancellables = Set<AnyCancellable>()
func bind() {
LaunchAtLogin
.publisher
.assign(to: \.isLaunchAtLoginEnabled, on: self)
.store(in: &cancellables)
}
} StoryboardsBind the control to the import Cocoa
import LaunchAtLogin
final class ViewController: NSViewController {
@objc dynamic var launchAtLogin = LaunchAtLogin.kvo
} How does it work?The package bundles the helper app needed to launch your app and copies it into your app at build time. FAQI'm getting a “No such file or directory” error when archiving my appPlease ensure that the LaunchAtLogin run script phase is still below the “Embed Frameworks” phase. The order could have been accidentally changed. The build error usually presents itself as:
The size of my app increased after adding |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论