简体   繁体   English

锁屏快速小部件仅适用于 iOS 16 用户

[英]Lockscreen swift widget only available to iOS 16 users

I have multiple widgets that are for iOS 14 users and above.我有多个适用于 iOS 14 及更高版本用户的小部件。 But with the new lockscreen widgets, it's only available to iOS 16 users.但有了新的锁屏小部件,它仅适用于 iOS 16 用户。 How can I only make the bottom two widgets for iOS 16 users?我怎样才能只为 iOS 16 用户制作底部的两个小部件? If I uncomment the top line then I believe it will make all widgets only available to iOS 16 users but I can't do that, I want my users to be able to continue using the home screen widgets if they're on iOS 14-15.如果我取消注释第一行,那么我相信它将使所有小部件仅适用于 iOS 16 用户,但我不能这样做,我希望我的用户能够继续使用主屏幕小部件(如果他们在 iOS 14 上)- 15.

import WidgetKit
import SwiftUI


//@available(iOSApplicationExtension 16.0, *)
@main
struct Widgets: WidgetBundle {
    @WidgetBundleBuilder
    var body: some Widget {
        Widget1()
        Widget2()
        Widget3()
        LockscreenWidget1()
        LockscreenWidget2()
    }
}

Just use the #available attribute instead:只需使用#available属性即可

import WidgetKit
import SwiftUI

@main
struct Widgets: WidgetBundle {
    @WidgetBundleBuilder
    var body: some Widget {
        Widget1()
        Widget2()
        Widget3()
        
        if #available(iOSApplicationExtension 16.0, *) {
            LockscreenWidget1()
            LockscreenWidget2()
        }
    }
}

This will make the entire struct work on iOS 14 while making the smaller lock screen subset just for iOS 16+.这将使整个结构在 iOS 14 上工作,同时为 iOS 16+ 制作更小的锁屏子集。 You might be interested in this forum discussion .您可能对此论坛讨论感兴趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM