Post

Replies

Boosts

Views

Activity

onContinueUserActivity not working on first app launch
HI, I'm trying to deeplink from my widget to a view in my app. I'm using the "SwiftUI app lifecycle". This the code I'm currently using: var body: some Scene { WindowGroup { RootView() .onContinueUserActivity("NextDeparturesWidgetConfigurationIntent") { userActivity in guard let configuration: NextDeparturesWidgetConfigurationIntent = userActivity .widgetConfigurationIntent(), let stationEntity = configuration.stationEntity else { return } NotificationCenter.default.post(name: .onOpenStation, object: stationEntity.id) } } } It is working fine when the app is already running (in the background). However when the app is "cold starting" (ie. not in memory) onContinueUserActivity is never called. I tried adding a UIApplicationDelegateAdaptor: func application( _ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions ) -> UISceneConfiguration { if let userActivity = options.userActivities.first { let configuration: NextDeparturesWidgetConfigurationIntent? = userActivity.widgetConfigurationIntent() // casting fails } return UISceneConfiguration( name: nil, sessionRole: connectingSceneSession.role ) } I can see that the activity is received but it is never casted to NextDeparturesWidgetConfigurationIntent. What am I missing ?
3
1
508
Jul ’24
Is it okay to use @State to store object ref instead of @StateObject
Hi, I want to display a sheet bound to an object using .sheet(item: $someObject content: <#T##(Identifiable) -> View#>) However if item is a class we can't use @StateObject var someObject: SomeObject? because an optional cannot conform to observable object. As I don't have any changing property and do not need the view to be refreshed once passed to the sheet I used @State and it seems to be working fine. Here is a minimal example of what I'm doing. import SwiftUI class SomeObject: Identifiable {   let id = 1   let content = "Hello world" } class SomeObjectStore {   static let shared = SomeObjectStore()   var objects = [SomeObject()]   private init() {} } struct ContentView: View {   @State private var someSheetPresentedObject: SomeObject?   var body: some View {     Button("Open view") {       someSheetPresentedObject = SomeObjectStore.shared.objects.first     }     .sheet(item: $someSheetPresentedObject) { someObject in       Text(someObject.content)     }   } } It seems okay because SwiftUI only needs to know if there is a reference to someSheetPresentedObject or not to present the sheet. I know that the Text won't be updated if SomeObject.content changes but I'm only displaying it once so it's not an issue. My question is: is it okay to do this for this specific case ?
2
0
478
Oct ’22
Is it safe to enable js with WKWebView loadFileURL ?
We are using WKWebView to render local files that we load using WKWebView loadFileURL's method. We use the webview to render "rich text" files like docx, xlsx. Until then we disabled js. However we discovered that disabling js also disabled the ability to switch pages in an xlsx document. Enabling js should be safe as js should be escaped in a correctly formatted xlsx file but we were wondering if it would be a security risk if someone managed to craft an xlsx which would potentially execute malicious js ?
0
0
433
Nov ’21
Uploading large amount of data using background upload task
Hello, I’m trying to upload the user’s entire photo library to a server so this can mean thousands of files. To achieve this task I'm trying to use a background URLSessionConfiguration with the following steps: Fetch all the phassetid For each phassetid, export the asset to my container Create a file upload task using the background session However I read some post on the forum which discourage using a background session for this kind of task (Moving to Fewer, Larger Transfers) - https://developer.apple.com/forums/thread/14853 and according to this post BackgroundTasks could be a better fit. I also noticed that it looks like I’m hitting some kind of rate limiter. Even with the app in the foreground, the transfers stop reporting progress after some time and then start reporting again after a small amount of time. This doesn't happen with a normal URLSessionConfiguration. So I was wondering if it was indeed the way to go or if there was some better/other way to do it ?
4
0
2.1k
Mar ’21