Post

Replies

Boosts

Views

Activity

How to setup SharePlay reliably?
Hi, I’m developing an app that uses SharePlay. In specific, I’m using ShareLink in my SwiftUI-based app so that when 2 devices come close, it will start SharePlay via AirDrop, just like how Name Drop works (the animation is super cool, btw). However, I’ve notice that SharePlay doesn’t start reliably under the following conditions: Do both devices need to be signed in using different Apple ID? I wish it works with the same Apple ID. When both devices are running my app, the sharing does not seem to start; maybe both of them are trying to be the host app? When I try to demo this NameDrop-like transaction via Zoom, it usually doesn’t work; maybe because the cable is connected in Lightening port? Is some Mac app (in my case, Zoom or even QuickTime) capturing the screen of the device make it less likely to have successful SharePlay transaction? Thanks!
0
0
329
Jun ’24
Inner UIScrollView and outer UIPanGestureRecognizer
Hi, If there are nested UIScrollViews, they will work together nicely; when the inner scroll view reaches the end of contentSize, the outer scroll view will start scrolling. Can we do the same with inner UIScrollView and outer UIView that has UIPanGestureRecognizer? I’ve tried using UIGestureRecognizerDelegate and return true in gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:) but that will scroll the inner UIScrollView and fire the outer UIPanGestureRecognizer at the same time. Thanks!
1
0
293
Jun ’24
CloudKit push notification not working on Sonoma
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.
0
0
429
Jan ’24
Cannot schedule background tasks in SwiftUI-based Watch app
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!
1
0
648
Jun ’23
Xcode 14 Beta 3: Mac app icon not showing in macOS Ventura
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
1
0
1k
Jul ’22
How to use iOS15-specific modifiers in SwiftUI on iOS 14 and earlier?
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!
2
0
5.3k
Sep ’21
Deselect List with animation in SwiftUI
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,
1
0
874
Jul ’21
Where to create View Model (or observed object) in SwiftUI?
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,
3
0
935
Jul ’21
How to specify different list style in .listStyle() based on current device?
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,
2
0
1.1k
Jul ’21
barTintColor not working in iOS 15
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!
24
0
82k
Jun ’21
How to add/test my widget in Notification Center in macOS Big Sur?
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.
3
0
1.1k
Oct ’20