WidgetKit

RSS for tag

Show relevant, glanceable content from your app on iOS and iPadOS Home Screen and Lock Screen, macOS Desktop, Apple Watch Smart Stack and Complications, and in StandBy mode on iPhone.

Posts under WidgetKit tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

ControlWidgetToggle icon format
What format can the image be in for a ControlWidgetIcon? Can we use .svg and .png? Or does it have to be a systemImage? In XCode16-beta4 this code worked: AppIntentControlConfiguration( kind: WidgetConfig.Constants.controlCenterLock, provider: Provider()) { value in ControlWidgetToggle( "Lock/Unlock", isOn: !value.isLocked, action: LockUnlockToggleIntent(), valueLabel: { isUnlocked in Label( isUnlocked ? "Unlocked" : "Locked", image: isUnlocked ? "controlUnlocked" : "controlLocked") }) }) Where "controlUnlocked"/"controlLocked" were the names of Assets in the Widget extension asset catalogue. But in XCode-beta 6, the icons show a question mark. I can only get icons to show by using systemImage Label( isUnlocked ? "Unlocked" : "Locked", systemImage: isUnlocked ? "lock.open": "lock.fill" ) Is it a bug that it isn't loading the icons? Is there a format for the icons? Or are only systemImage icons supported?
2
0
304
Sep ’24
ControlWigdet Open APP with URL
This code can open app, but the deep link is not send to the app. It doesn't seem to call the UIApplicationDelegate's "application(_:open:options:)" method, so I can't read the link string that was passed in func perform() async throws -> some IntentResult & OpensIntent { guard let url = URL(string: "myapp://myappintent") else { // throw an error of your choice here } return .result(opensIntent: OpenURLIntent(deepLink)) }
1
1
399
Aug ’24
minimumScaleFactor for Text in widgets scales the text.
Hi, In my widgets, I use minimumScaleFactor to ensure that my text is readable. In iOS 18.0 beta 6 and iOS18.0 beta 7, my texts suddenly became very small. It seems that minimumScaleFactor acts like if it was applying the given scale value to the text. minimumScaleFactor(0.1) seems to display the text 90% smaller than the text without calling minimumScaleFactor. minimumScaleFactor(0.5) seems to display the text 50% smaller than the text without calling minimumScaleFactor. Is this a bug, of is there an unexpected change in the API ? Edit : I have created FB14890220, in case this message remains unseen.
8
2
814
Sep ’24
iOS 18 new ControlWidgetButton custom image/icon/symbol not displayed
Hello, I am trying to create a custom control with the new WidgetKit control widget APIs. In my custom control, I want to display a custom image, in fact a custom symbol. The custom symbol is not displayed with latest iOS 18 Seed 7 (22A5346a). Only system symbols are displayed. I don't find any information about it in the WidgetKit Apple Developer Documentation. ControlWidgetButton(action: MyIntent()){ Label(title: { Text("My Custom Control") }, icon: { Image("mycustomsymbol") //NOT DISPLAYED // Image(systemName: "rectangle.portrait.inset.filled") IS DISPLAYED }) } There was no issue with custom symbols in beta 4. Now since beta 5, custom symbols are not displayed. I wonder if this is a bug or this is intended. Can you help me ? I filed a feedback FB14888220 Thank you
2
2
616
2w
iOS18 Control Widget that opens parent app
I feel like this is probably really easy and hopefully I'm just doing something stupid, but I can't get a control to open the app it belongs to. Taking the intent itself directly from the example code, and it does nothing when the button is pressed. struct OpenAppWidget: ControlWidget { var body: some ControlWidgetConfiguration { StaticControlConfiguration( kind: "com.dfjkldfsfrw.ControlCenterWidgetDemo.OpenApp" ) { /// This one - based on the demo code - doesn't work on simulator or device ControlWidgetButton(action: LaunchAppIntent()) { Label("Launch App", systemImage: "arrow.up.right") } } .displayName("Launch App") .description("A an example control that launches the parent app.") } } struct LaunchAppIntent: OpenIntent { static var title: LocalizedStringResource = "Launch App" @Parameter(title: "Target") var target: LaunchAppEnum } enum LaunchAppEnum: String, AppEnum { case timer case history static var typeDisplayRepresentation = TypeDisplayRepresentation("Productivity Timer's app screens") static var caseDisplayRepresentations = [ LaunchAppEnum.timer : DisplayRepresentation("Timer"), LaunchAppEnum.history : DisplayRepresentation("History") ] } I've tried adding a perform( function to the intent, and setting openAppWhenRun to true, but they don't seem to make a difference. I've also tried using an OpenURLIntent in the result of the button's intent to open the app based on a custom url scheme, but whilst that seems to work in the simulator, it doesn't work on a real device. What am I missing?
3
2
888
Aug ’24
How can I share code between app and widget that contains uiapplication?
OK, so I'm trying to share some utils classes for logging. The problem is a use-case where I want to create a debug notification. However, inside the app, I want to show a popup instead if the app is showing, but I can't share that code because it uses UIApplication.shared.ApplicationState. I've tried gating it off with all sorts of methods, @available etc. but I get compilation error "unavailable for application extensions" Example of me trying: static func doNotification(_ header: String, message: String) { //so I'm trying to gate off the code that only can be called in an extension , and in addition I have @available below if(isAppExtension()){ doNotificationFromExtension(header, message: message) }else{ doNotificationFromApp(header, message: message) } } @available(iOSApplicationExtension, unavailable) static func doNotificationFromApp(_ header: String, message: String) { let state = UIApplication.shared.applicationState if state != .active { //my dialog handler in-app popup }else{ NotifUtils.createLocalNotification(message, header: header, category: NOTIFICATION_CATEGORY_DEBUG, playSound: false) } } //here I know that I'm in an extension, so app isn't showing - always local notification static func doNotificationFromExtension(_ header: String, message: String) { NotifUtils.createLocalNotification(message, header: header, category: NOTIFICATION_CATEGORY_DEBUG, playSound: false) } static func isAppExtension() -> Bool { return Bundle.main.executablePath?.contains(".appex/") ?? false } Is there any way to share the code like this? The reason I want to do this is because I have various live activity code that I'd want to re-use, but this is a show.-stopper.
3
0
416
Aug ’24
Widget crash
Hello, apple! I get a crash log in development. I check the package contents and find the file does exist in path ''/private/var/containers/Bundle/Application/8BD48BB3-FA58-498B-AE61-559D415D6F18/MyApp.app/Frameworks/MyFramework.framework/MyFramework'' Please help to check if this is our project issue or system issue. The content is: Incident Identifier: 39F9567A-E204-4FC0-932E-078CB082C9D0 CrashReporter Key: 4fd7a4d1d72f1b6158af9d5d4ff15c85f6adc6f9 Hardware Model: iPhone13,4 Process: WidgetExtension [1259] Path: /private/var/root/Library/Caches/com.apple.containermanagerd/System/Dead/temp.aEu43U/655B4729-5B26-4E43-A0DF-BAB6E8D03E83/MyApp.app/PlugIns/WidgetExtension.appex/WidgetExtension Identifier: WidgetExtension Version: ??? Code Type: ARM-64 (Native) Role: Unspecified Parent Process: launchd [1] Coalition: bundleId [1033] Date/Time: 2024-08-16 15:48:56.1150 +0800 Launch Time: 2024-08-16 15:48:56.0226 +0800 OS Version: iPhone OS 17.5 (21F5073b) Release Type: Beta Baseband Version: 4.50.06 Report Version: 104 Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Termination Reason: DYLD 1 Library missing Library not loaded: @rpath/MyFramework.framework/MyFramework Referenced from: <14B7FD51-C300-3B5E-8A13-4C681DE0B359> /Volumes/VOLUME/*/MyApp.app/PlugIns/WidgetExtension.appex/WidgetExtension Reason: tried: '/usr/lib/swift/MyFramework.framework/MyFramework' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/MyFramework.framework/MyFramework' (no such file), '/private/var/containers/Bundle/Application/8BD48BB3-FA58-498B-AE61-559D415D6F18/MyApp.app/PlugIns/WidgetExtension.appex/Frameworks/MyFramework.framework/MyFramework' (no such file), '/private/var/containers/Bundle/Application/8BD48BB3-FA58-498B-AE61-559D415D6F18/MyApp.app/PlugIns/WidgetExtension.appex/Frameworks/MyFramework.framework/MyFramework' (no such file), '/private/var/containers/Bundle/Application/8BD48BB3-FA58-498B-AE61-559D415D6F18/MyApp.app/Frameworks/MyFramework.framework/MyFramework' (no such file), '/usr/lib/swift/MyFramework.framework/MyFramework' (no such file, not in dyld cache), (terminated at launch; ignore backtrace) Triggered by Thread: 0 Thread 0 Crashed: 0 dyld 0x1b3d49cd8 __abort_with_payload + 8 1 dyld 0x1b3d55450 abort_with_payload_wrapper_internal + 104 2 dyld 0x1b3d55484 abort_with_payload + 16 3 dyld 0x1b3ce2e00 dyld4::halt(char const*, dyld4::StructuredError const*) + 304 4 dyld 0x1b3cf059c dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 4088 5 dyld 0x1b3d14c48 start + 1724 Thread 0 crashed with ARM Thread State (64-bit): x0: 0x0000000000000006 x1: 0x0000000000000001 x2: 0x000000016bceac50 x3: 0x00000000000000c8 x4: 0x000000016bcea850 x5: 0x0000000000000000 x6: 0x0000000000000000 x7: 0x0000000000000ff0 x8: 0x0000000000000020 x9: 0x000000016bcea7c6 x10: 0x000000000000000a x11: 0x0000000000000000 x12: 0x0000000000000031 x13: 0x1000000000000000 x14: 0x0000000000000004 x15: 0x0000000000008000 x16: 0x0000000000000209 x17: 0x00000001b3ce1884 x18: 0x0000000000000000 x19: 0x0000000000000000 x20: 0x000000016bcea850 x21: 0x00000000000000c8 x22: 0x000000016bceac50 x23: 0x0000000000000001 x24: 0x0000000000000006 x25: 0x000000016bceb720 x26: 0x000000016bceb6c8 x27: 0x000000016bceb660 x28: 0x000000016bceb5d8 fp: 0x000000016bcea820 lr: 0x00000001b3d55450 sp: 0x000000016bcea7e0 pc: 0x00000001b3d49cd8 cpsr: 0x80001000 far: 0x0000000000000000 esr: 0x56000080 Address size fault Binary Images: 0x104114000 - 0x10411bfff WidgetExtension arm64 <14b7fd51c3003b5e8a134c681de0b359> /private/var/containers/Bundle/Application/8BD48BB3-FA58-498B-AE61-559D415D6F18/MyApp.app/PlugIns/WidgetExtension.appex/WidgetExtension 0x1b3cd8000 - 0x1b3d64ef7 dyld arm64e <da3896ecbf5234efb392a744373c3faa> /usr/lib/dyld 0x0 - 0xffffffffffffffff ??? unknown-arch <00000000000000000000000000000000> ???
2
0
285
Aug ’24
Would like feedback on handling multiple button presses while live activity intent Is processing
I am working on a live activity with a button that will do a network call when pressed on. I want to make sure that it can only be pressed once, and then ignored while the request is processed. This is what I did: Since it seems that a new intent object is created for each button press, I am using a static synchroniser like this: private var _isBusy: Bool = false private var _timestamp: Date? = nil private let queue: DispatchQueue private let resetInterval: TimeInterval init(resetInterval: TimeInterval = 60, queueLabel: String = "default.synchronizedBoolQueue") { self.resetInterval = resetInterval self.queue = DispatchQueue(label: queueLabel) } var isBusy: Bool { get { return queue.sync { return _isBusy } } set { queue.sync { _isBusy = newValue } } } func setIfNotBusy() -> Bool { return queue.sync { let now = Date() if let timestamp = _timestamp { if now.timeIntervalSince(timestamp) > resetInterval { // Reset if it was more than the specified interval ago _isBusy = false _timestamp = nil } } if !_isBusy { _isBusy = true _timestamp = now return true } return false } } func clearBusy() { queue.sync { _isBusy = false _timestamp = nil } } } Then, in my intent I have: private static let synchronizedBoolean = SynchronizedBoolean(queueLabel: "myIntent") ... func perform() async throws -> some IntentResult { NSLog("---LIVE perform() called") if(!UserEventIntent.synchronizedBoolean.setIfNotBusy()){ NSLog("---LIVE Was already in progress!") }else{ //doing intent logic here UserEventIntent.synchronizedBoolean.clearBusy() } } I am pretty new to Swift, so my hope is that someone more experienced than me could tell me if this a reasonable approach or if I'm missing anything? A big question - let's say I go into the perform() method, and while I'm in there, the user presses the button and the intent is called again. I get the "already in progress", but the method must still provide a result. Will that effect the intent already in progress? Thoughts much appreciated.
2
0
297
Aug ’24
com.apple.dt.deviceprocesscontrolservice Code=8
Hello, I get this error: How can I fix it and hope you can help me. greetings Fabian SendProcessControlEvent:toPid: encountered an error: Error Domain=com.apple.dt.deviceprocesscontrolservice Code=8 "Failed to show Widget 'de.polygondata.BikeComputer.BikeComputerWidget' error: Error Domain=FBSOpenApplicationServiceErrorDomain Code=1 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedFailureReason=The request was denied by service delegate (SBMainWorkspace)., BSErrorCodeDescription=RequestDenied, NSUnderlyingError=0x600000c37150 {Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (de.polygondata.BikeComputer.BikeComputerWidget)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (de.polygondata.BikeComputer.BikeComputerWidget)}}, FBSOpenApplicationRequestID=0xbf3b, NSLocalizedDescription=The request to open "com.apple.springboard" failed.}." UserInfo={NSLocalizedDescription=Failed to show Widget 'de.polygondata.BikeComputer.BikeComputerWidget' error: Error Domain=FBSOpenApplicationServiceErrorDomain Code=1 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedFailureReason=The request was denied by service delegate (SBMainWorkspace)., BSErrorCodeDescription=RequestDenied, NSUnderlyingError=0x600000c37150 {Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (de.polygondata.BikeComputer.BikeComputerWidget)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (de.polygondata.BikeComputer.BikeComputerWidget)}}, FBSOpenApplicationRequestID=0xbf3b, NSLocalizedDescription=The request to open "com.apple.springboard" failed.}., NSUnderlyingError=0x600000c36e50 {Error Domain=FBSOpenApplicationServiceErrorDomain Code=1 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedFailureReason=The request was denied by service delegate (SBMainWorkspace)., BSErrorCodeDescription=RequestDenied, NSUnderlyingError=0x600000c37150 {Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (de.polygondata.BikeComputer.BikeComputerWidget)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (de.polygondata.BikeComputer.BikeComputerWidget)}}, FBSOpenApplicationRequestID=0xbf3b, NSLocalizedDescription=The request to open "com.apple.springboard" failed.}}} Domain: DTXMessage Code: 1 User Info: { DVTErrorCreationDateKey = "2024-08-16 17:14:32 +0000"; } SendProcessControlEvent:toPid: encountered an error: Error Domain=com.apple.dt.deviceprocesscontrolservice Code=8 "Failed to show Widget 'de.polygondata.BikeComputer.BikeComputerWidget' error: Error Domain=FBSOpenApplicationServiceErrorDomain Code=1 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedFailureReason=The request was denied by service delegate (SBMainWorkspace)., BSErrorCodeDescription=RequestDenied, NSUnderlyingError=0x600000c37150 {Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (de.polygondata.BikeComputer.BikeComputerWidget)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (de.polygondata.BikeComputer.BikeComputerWidget)}}, FBSOpenApplicationRequestID=0xbf3b, NSLocalizedDescription=The request to open "com.apple.springboard" failed.}." UserInfo={NSLocalizedDescription=Failed to show Widget 'de.polygondata.BikeComputer.BikeComputerWidget' error: Error Domain=FBSOpenApplicationServiceErrorDomain Code=1 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedFailureReason=The request was denied by service delegate (SBMainWorkspace)., BSErrorCodeDescription=RequestDenied, NSUnderlyingError=0x600000c37150 {Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (de.polygondata.BikeComputer.BikeComputerWidget)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (de.polygondata.BikeComputer.BikeComputerWidget)}}, FBSOpenApplicationRequestID=0xbf3b, NSLocalizedDescription=The request to open "com.apple.springboard" failed.}., NSUnderlyingError=0x600000c36e50 {Error Domain=FBSOpenApplicationServiceErrorDomain Code=1 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedFailureReason=The request was denied by service delegate (SBMainWorkspace)., BSErrorCodeDescription=RequestDenied, NSUnderlyingError=0x600000c37150 {Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (de.polygondata.BikeComputer.BikeComputerWidget)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (de.polygondata.BikeComputer.BikeComputerWidget)}}, FBSOpenApplicationRequestID=0xbf3b, NSLocalizedDescription=The request to open "com.apple.springboard" failed.}}} Domain: DTXMessage Code: 1
1
0
420
Sep ’24
Unable to get widgetConfigurationIntent from NSUserActivity
I have a simple lock screen widget that when tapped, should open a certain flow in my app. This works fine when the main app is already running, but when tapped while the app is not running, the app launches, but it doesn't open the flow I want it to. When I debug it (see flow below), it seems that the problem come from the widgetConfigurationIntent(of:) function on NSUserActivity. When the app is cold launched, I get the expected NSUserActitivity, but the function above returns nil. That same piece of code returns a valid WidgetConfigurationIntent if the app is already running. Any ideas what might go wrong? There's nothing in the documentation hinting about why this might happen, so I feel a bit lost. BTW, this is how a debug opening from scratch with a lock screen widget: Select "Wait for the executable to be launched" in the scheme editor in Xcode. Make sure the app is not running on device or simulator Start debugging session in Xcode (app is built but not opened) Lock device, tap already installed lock screen widget. App launches and my breakpoint is hit.
0
0
206
Aug ’24
iOS18 Control Widget dynamic switch intent
Objective: When the app is running, directly operate the app without launching it. When the app is not started, wake up the app to perform the corresponding operation. Premise: AppIntent's openAppWhenRun can dynamically control whether the app is launched, but the variable itself cannot be changed. Therefore, the idea is to refresh the widget when the app is started or terminated, displaying different content (binding different intents) to achieve the goal. However, there are persistent issues during code implementation. struct ControlWidgetContent: ControlWidgetTemplate { var body: some ControlWidgetTemplate { if (applaunched) { return ControlWidgetButton(action: Aintent()) { Label("xxxx", systemImage: "calendar") } } else { return ControlWidgetButton(action: Bintent()) { Label("xxxx", systemImage: "calendar") } } } } @available(iOS 18.0, *) struct ControlWidgetContent: ControlWidget { let kind: String = "ControlWidgetInterface" var body: some ControlWidgetConfiguration { StaticControlConfiguration( kind: kind ) { ControlWidgetContent() }.displayName("xxxx") } } it preports error: Function declares an opaque return type 'some ControlWidgetTemplate', but the return statements in its body do not have matching underlying types Return statement has underlying type 'ControlWidgetButton<Label<Text, Image>, ControlWidgetButtonDefaultActionLabel, PlayDayRcmdIntent>'
2
0
500
Aug ’24
ios18 Beta6 Widget can't running with IPhone, also do not appear on Adding widgets list
ios18 Beta6 Widget can't running with IPhone, also do not appear on Adding widgets list。anyone can help me to fix it? SendProcessControlEvent:toPid: encountered an error: Error Domain=com.apple.dt.deviceprocesscontrolservice Code=32 "Show Notification Center Widget timed out." UserInfo={NSLocalizedDescription=Show Notification Center Widget timed out.} Domain: DTXMessage Code: 1 User Info: { DVTErrorCreationDateKey = "2024-08-15 09:19:19 +0000"; } SendProcessControlEvent:toPid: encountered an error: Error Domain=com.apple.dt.deviceprocesscontrolservice Code=32 "Show Notification Center Widget timed out." UserInfo={NSLocalizedDescription=Show Notification Center Widget timed out.} Domain: DTXMessage Code: 1 System Information macOS Version 14.5 (Build 23F79) Xcode 15.4 (22622) (Build 15F31d) Timestamp: 2024-08-15T17:19:19+08:00
2
3
403
Aug ’24
iOS 18 seems to have broken animations in Widgets
In iOS 18 the same animations inside the main app and a widget behave very differently. This was not the case in iOS 17 and it seems like a regression. Bellow I described the full source code for an example application to reproduce the issue. But I'll try to describe it as well. I'm using a simple bounce animation .animation(.bouncy(duration: 0.25, extraBounce: 0.3).delay(delay), value: toggle) on multiple views with a variable delay to create an effect of staggered motion. In the main app, the bounce parameters and delays behave exactly as specified, but on the widget they seem to be largely ignored and the timing functions for the animations look very different. It's also visible that on some elements the delay is ignored completely and animation starts right away. I double-checked that the whole animation duration never exceeds 2 seconds as I saw that that's a hard cutoff for animations in widgets. In iOS 17 the same code works identically inside the main app and the widget. The issue is only present in iOS 18. Another point is that in Xcode previews for widgets animations behave as expected. The issue is only present on the device or in the simulator. Maybe there is some additional limitation introduced for widget animations? I could not find anything relevant in the documentation, unfortunately, so I'd appreciate any help here. Please let me know if I can provide any additional information that would help. Thank you! Example app source code: ContentView.swift // ContentView.swift import SwiftUI struct ContentView: View { @State private var toggle: Bool = true var body: some View { VStack { BounceView(toggle: toggle) Button("Toggle Bounce") { toggle.toggle() } } .padding() } } BounceView.swift import SwiftUI let ROWS: Int = 5 let COLS: Int = 5 let MAX_DISTANCE: Double = sqrt(pow(Double(COLS - 1), 2) + pow(Double(ROWS - 1), 2)) struct BounceView: View { let toggle: Bool var body: some View { VStack(spacing: 3) { ForEach(0..<ROWS, id: \.self) { y in HStack(spacing: 3) { ForEach(0..<COLS, id: \.self) { i in let distance: Double = sqrt(Double(y) * Double(y) + Double(i) * Double(i)) let influence = distance / MAX_DISTANCE let delay: Double = 0.4 * influence RoundedRectangle(cornerRadius: 4) .fill(.blue) .frame(width: 14, height: 14) .scaleEffect(toggle ? 1 : 0.1) .animation(.bouncy(duration: 0.25, extraBounce: 0.3).delay(delay), value: toggle) } } } } } } DemoWidget.swift import WidgetKit import SwiftUI struct Provider: TimelineProvider { func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date(), toggle: false) } func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) { let entry = SimpleEntry(date: Date(), toggle: false) completion(entry) } func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) { let currentToggle = UserDefaults.standard.bool(forKey: "animationToggle") let entries: [SimpleEntry] = [SimpleEntry(date: Date(), toggle: currentToggle)] let timeline = Timeline(entries: entries, policy: .atEnd) completion(timeline) } } struct SimpleEntry: TimelineEntry { let date: Date let toggle: Bool } struct DemoWidget: Widget { let kind: String = "DemoWidget" var body: some WidgetConfiguration { StaticConfiguration(kind: kind, provider: Provider()) { entry in VStack { BounceView(toggle: entry.toggle) Button( intent: ToggleAppIntent(), label: { Text("Toggle Bounce") } ) } .containerBackground(.fill.tertiary, for: .widget) } .configurationDisplayName("My Widget") .description("This is an example widget.") } } #Preview(as: .systemMedium) { DemoWidget() } timeline: { SimpleEntry(date: .now, toggle: true) SimpleEntry(date: .now, toggle: false) } ToggleAppIntent.swift import Foundation import WidgetKit import AppIntents struct ToggleAppIntent: AppIntent { static var title: LocalizedStringResource = "Toggle App Intent" func perform() async throws -> some IntentResult { let currentToggle = UserDefaults.standard.bool(forKey: "animationToggle") UserDefaults.standard.set(!currentToggle, forKey: "animationToggle") WidgetCenter.shared.reloadTimelines(ofKind: "DemoWidget") return .result() } }
4
2
1k
Aug ’24
iOS18 Live Activity failed to show sometimes
In a music streaming app, when using Activity.request to activate the Dynamic Island, the system’s Now Playing interface appears correctly. However, the app's live activities, lock screen, and other related features fail to display properly. During debugging, the following code is used: activity = try Activity.request(attributes: attributes, contentState: contentState, pushType: .token) if !NMABTestManager.default().is(inTest: "FH-NewLiveActivityPush") { // Listen to push token updates if activity != nil { tokenUpdatesTask?.cancel() tokenUpdatesTask = Task.detached { for await tokenData in self.activity!.pushTokenUpdates { let mytoken = tokenData.map { String(format: "%02x", $0) }.joined().uppercased() // pushToken is Data, needs to be converted to String using the above method before being passed to the server self.pushToken = mytoken } } } } } catch (let error) { print("Error Starting Live Activity: \(error.localizedDescription)") } In this scenario, the push token is returned correctly, and no errors are triggered. This issue did not occur in iOS 17 but appears sporadically in iOS 18. Once it occurs, it cannot be resolved through restarting or other means. feedbackid:FB14763873, i upload my sysdisagnose
2
0
685
Aug ’24
Can TodayExtensions and WidgetKit Coexist in an App
I understand that TodayExtension will be deprecated in iOS 18, and we have integrated WidgetKit into our app. However, we have encountered some issues during the app update process. Specifically, we noticed that the TodayExtension might not appear in the tools list or sometimes the TodayExtension appear "Unable to Load" Could you please advise on the possible causes of this issue? Is there a way to resolve it if we want to keep both types of widgets active?
3
0
736
Aug ’24
iOS18 AudioPlaybackIntent respond too slow when app not launched
here's my case, i develop a control widget, user can push a controlwidget to play music without open the app. i bind a AudioPlaybackIntent to the widget. when user click the widget, the app will receive the intent and start to play music. it works perfect when app running in background or foreground. but when app not launched, the respond is too slow, it takes several seconds to start play music. is there any way to make the respond faster when app not launched? if i want to do something when app not launched, what should i do?
2
0
577
Aug ’24
iOS18 Control Widget custom symbol preview failed
i export apple SF as custom sf for test. code is simple: var body: some ControlWidgetConfiguration { StaticControlConfiguration( kind:"ControlWidgetConfiguration" ) { ControlWidgetButton(action: DynamicWidgetIntent()) { Text("test") Image("custom_like") } }.displayName("test") } as we can see, it can't show image in the preview. but it can show image in the Control widget center. am i do some thing wrong?
4
7
497
Aug ’24