Posts

Post not yet marked as solved
0 Replies
242 Views
I have an app that uses CloudKit push notification (CKDatabaseSubscription) and it's been working all along on Ventura 13.5/Xcode 15.0. But since I upgraded my Mac to Sonoma 14.3/Xcode 15.2, my app no longer receives push notification (didReceiveRemoteNotification is not called) on the Mac. Is this a known issue of either Sonoma or Xcode 15.2? FYI, the same code works perfectly on iOS 17.2.
Posted Last updated
.
Post marked as solved
3 Replies
3.7k Views
Hi, I'm trying to create a ViewController that extends UIHostingController and host an AttachmentView there. Also, I would like to pass an environment object to the AttachmentView, but I get a compile error because the type of rootView does not match what I specify in UIHostingController. How can I get this code to compile? Thanks!
Posted Last updated
.
Post not yet marked as solved
1 Replies
453 Views
How do I schedule a background task in my SwiftUI-based Watch app? When I call the following method: WKApplication.shared() .scheduleBackgroundRefresh( withPreferredDate: Date.init(timeIntervalSinceNow: 15.0 * 60.0), userInfo: "MY_FIRST_UPDATE" as NSSecureCoding & NSObjectProtocol) { error in if error != nil { // Handle the scheduling error. fatalError("*** An error occurred while scheduling the background refresh task. ***") } print("*** Scheduled! ***") } the app crashes: 2023-06-21 16:04:48.730140+0900 MyWatchApp[416:109084] [default] -[WKApplication scheduleBackgroundRefreshWithPreferredDate:userInfo:scheduledCompletion:]:131: Critical failure. Simulating crash: Condition failed:"NO". -[WKApplication scheduleBackgroundRefreshWithPreferredDate:userInfo:scheduledCompletion:] requires that your WKApplicationDelegate (null) implement handleBackgroundTasks: My app is defined as follows: @main struct MyWatchApp: App { @WKExtensionDelegateAdaptor(ExtensionDelegate.self) var delegate @StateObject var viewModel = MainViewModel.shared var body: some Scene { WindowGroup { ContentView() ... // bunch of stuff here } .backgroundTask(.appRefresh) { context in // I want to perform background task here await viewModel.handleBackgroundRefresh() } } } class ExtensionDelegate: NSObject, WKExtensionDelegate { func applicationDidFinishLaunching() { ... } func applicationDidBecomeActive() { ... } func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) { // just in case, though this is not helping... } } I'm just following your instructions here: https://developer.apple.com/documentation/watchkit/background_execution/using_background_tasks Do I need to put some entry in my Info.plist? Or any capability I need to add? (I've added "Background Modes" with "Remote notifications" checked because I'm using CloudKit) Any help is very much appreciated!
Posted Last updated
.
Post not yet marked as solved
3 Replies
6.3k Views
Hi,When dragging a view inside UIScrollView using UIDragInteraction/UIDropInteraction, the scroll view *automatically* scrolls as you drag your view near the edge of the screen. How can you prevent this behavior? I want to disable *only* the automatic scrolling, not the scrolling itself, so that the user can scroll with the second finger if he so chooses. I know I can disable scrolling using isScrollEnabled, but this will also disable the user-initiated scrolling. Thanks.
Posted Last updated
.
Post marked as solved
1 Replies
874 Views
Hi, I have an AppKit-based Mac app which was originally released in 2017. Since then, I've been constantly adding new features and now, I'm trying to add WeatherKit and other new features in macOS Ventura. The problem is that Xcode 14 beta 3 fails to show my app's icon on the Dock: The app icon is shown properly in Xcode and also in Finder: When I open the exact same Xcode project and run it in Xcode 13/Monterey, the app icon is shown properly in the Dock. Any help is appreciated! Best, Kaz
Posted Last updated
.
Post marked as solved
18 Replies
79k Views
Hi, When I run the following code in application(_ :didFinishLaunchingWithOptions) in iOS 15, the bar color turns transparent (thus, showing the black background underneath), while the same code works fine in iOS 14.5: UINavigationBar.appearance().isTranslucent = false UINavigationBar.appearance().barTintColor = .red Here's the screenshots of Simulators running iOS 14.5 and iOS 15: I'm using Xcode 13 on macOS Big Sur 11.4. Thanks!
Posted Last updated
.
Post not yet marked as solved
1 Replies
733 Views
Hi, I'm having a hard time trying to solve this impossibly small problem in SwiftUI. I have a list like this: struct ContentView: View { var body: some View { List { Button(action: { print("hello") }, label: { Text("Hello") }) } } } And every time I tap on it, the row deselect without animation, but I want the same effect as UITableView.deselectRow(at:animated:). Why is this so hard or am I missing something? I don't want to use NavigationLink because I only want to execute code upon tap, not navigating to other view, unless it's possible to only execute code using NavigationLink... Thanks,
Posted Last updated
.
Post not yet marked as solved
2 Replies
4.5k Views
There are many new iOS15-specific modifiers that were added in SwiftUI. For example, we have a .focused() modifier, which can be used like this: TextField("Username", text: $username) .focused($focusedField, equals: .username) However, this code fails to compile if the app supports iOS 14 and earlier. How can I make this code to compile? Ideally, I'd like to do something like this: TextField("Username", text: $username) #if os(iOS, 15.0, *) .focused($focusedField, equals: .username) #endif But obviously this won't work because #if os() can only specify the target OS, not the version.. Thanks!
Posted Last updated
.
Post not yet marked as solved
3 Replies
699 Views
In SwiftUI, is it a good idea to create a view model (or observed object) in a View? For example, if I write a code like this: struct AView: View { ... public var body: some View { ... ForEach(...) { ... otherView } } private var otherView: some View { let model = OtherViewModel() return OtherView().environmentObject(model) } } I guess this will re-create OtherViewModel every time AView is refreshed, so maybe this is not a good approach after all? I thought about creating it in the constructor of AView, but if otherView is created multiple times using ForEach like the example above, it's difficult to know ahead of time how many of these models I need to create. Any suggestion is highly appreciated! Thanks,
Posted Last updated
.
Post marked as solved
2 Replies
875 Views
public var body: some View { List { ... } .listStyle(isPhone ? .plain : .sidebar) } When I write code like above, I get a compile error: "Member 'sidebar' in 'PlainListStyle' produces result of type 'SidebarListStyle', but context expects 'PlainListStyle'" It looks like the root cause is: Protocol 'ListStyle' can only be used as a generic constraint because it has Self or associated type requirements How can I solve this problem? Thanks,
Posted Last updated
.
Post marked as solved
1 Replies
669 Views
Hi, The Background Tasks framework introduced in iOS 13 is also available in Mac Catalyst 13.0 according to the documentation. However, the same code that runs on iOS 13 using the BGAppRefreshTaskRequest class does not work in my Mac Catalyst app. So I was wondering whether or not the Background Tasks framework is supposed to work in a Mac Catalyst app. Thanks!
Posted Last updated
.
Post not yet marked as solved
3 Replies
929 Views
I'm running the latest macOS Big Sur beta 9, and I have an AppKit app and added a widget extension using Xcode 12.2 beta 2. I can run my widget using WidgetKit Simulator and it's working great. However, when I click the date/time on the menu bar to show the Notification Center and click the "Edit Widgets" at the bottom, I don't have my app listed in the list of apps. I tried copying my app's executable and put it in the "Application" folder, but the app still does not show up. So how can I add/test my widget in Notification Center? Thank you.
Posted Last updated
.