- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发电池 WidgetKit ,但在更新电池电量时遇到问题经常够了。每次电池百分比变化时,我都希望更新 WidgetKit 。但是从我所做的所有阅读来看,这似乎是不可能的。我尝试每 5 分钟和每 15 分钟请求一个新的时间线,但没有成功。我在 AppStore 上看到一些应用程序有电池指示器,而且它经常更新。任何线索让他们完成这个?我看到有人在谈论使用后台获取。这不是最好的方法吗?我已经包含了我的代码,也许我实现错了?感谢对此的任何反馈!
提供者
struct Provider: TimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry(date: Date())
}
func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
let entry = SimpleEntry(date: Date())
completion(entry)
}
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
let currentDate = Date()
let newDate = Calendar.current.date(byAdding: .minute, value: 15, to: currentDate)
let timeline = Timeline(entries: [SimpleEntry(date: currentDate)], policy: .after(newDate!))
completion(timeline)
}
}
BatteryWidgetEntryView
struct BatteryWidgetEntryView : View {
var entry: Provider.Entry
var body: some View {
Text("\(Int(Self.battery * 100))")
.font(.largeTitle)
}
static let battery: Float = {
UIDevice.current.isBatteryMonitoringEnabled = true
let batteryLvl = UIDevice.current.batteryLevel
return batteryLvl
}()
}
最佳答案
您不能从 WidgetKit 中执行此操作,您必须从主机应用程序重新加载时间线。主机app监控电池状态和通话
WidgetCenter.shared.reloadTimelines(ofKind: "com.mybattery.widget")
触发 WidgetKit 的重新加载。
关于ios - 保持电池 iOS WidgetKit 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64850630/
我开发游戏已经有一段时间了,我开始意识到我的应用程序很快就会耗尽设备电池。我通过 XCode 仪器测量了能量消耗,一般在 17/20 范围内。我有一些背景动画,禁用它们似乎确实有帮助。出于好奇,我使用
我有两个原型(prototype)电池。如果 messagesArray[indexPath.row] 值为“”,则出现一个,如果该值包含字符,则出现另一个。其中一个单元格的行高大于第二个单元格的行高
我有一个弹出窗口,弹出窗口内部是一个相机按钮,我的相机工作正常,但顶部的电池符号与相机重叠,下面是屏幕截图。 如果有人知道答案,我们将不胜感激。 最佳答案 您可以隐藏该 View 的状态栏,这样它就不
有没有办法从 Android SDK 获取电池信息?比如剩余电池生命周期等等?我无法通过文档找到它。 最佳答案 这是一个简单的示例,可以让您了解电池的使用量、电池电压和温度。 将以下代码粘贴到 Act
我想删除状态栏(显示时间和电池状态)。就像在涂鸦跳跃或其他游戏中一样。 我怎样才能做到这一点? 谢谢 :) 最佳答案 http://iphonesdkdev.blogspot.com/2008/06/
已经阅读了关于同一主题的其他 SO 帖子,并且在以下方法之间做出决定: Thread 1与 Thread 2与 simple onLocationUpdate() 有人可以帮助我了解所有这些的利弊吗?
最近 google 推出了推送到设备服务,但它仅适用于 2.2 及更高版本。 我的应用程序中需要一个类似的系统,并且我正在尝试绕过限制。 问题是电池生命周期。由于必须立即通知用户有关服务器上的更改,我
Closed. This question needs to be more focused。它当前不接受答案。 想改善这个问题吗?更新问题,使其仅关注editing this post一个问题。 6
我有两个原型(prototype) TableViewCells。现在,一个只是另一个的复制粘贴。 BasicCell 和 BasicCell2 。我刚刚为 BasicCell2 复制了 BasicC
我目前正在为 iPhone 开发一个聊天客户端。服务器端有一个带有 Socket.IO 的 node.js,在 iPhone 上有一个 Socket.IO 客户端( https://github.co
所以我发现没有公开的方法来获取 watchKit 中的电池电量。 所以没有UIDevice.currentDevice().batteryLevel和WKInterfaceDevice不接缝有货。 在
由于 Google 在其网站上提供了适用于 Android L 的更新 SDK。我一直在尝试测试新的电池历史记录功能。 Google API 概述 website声称该工具在 sdk/tools 下可
我已经安装了全新的 Catalina 和 Android Studio。事实证明,当我启动模拟器时,模拟器进程会占用大量 CPU 周期。查看 adb shell 中的 top,我得到了一些我不理解的进
我修复了 iOS 7 的问题,导航栏是重叠 TableView 。 我用这个代码 //for help navigation bar overlap if ([self respondsToSelec
今天,小爱同学官微发布消息宣布,Redmi 小爱触屏音箱 Pro 正式推出,该机搭载 8 英寸屏幕,配备电池可不用时刻连接电源,售价 499 元,新品将于 9 月 9 日 0 点正式开售。 作
我是一名优秀的程序员,十分优秀!