Posts

Post not yet marked as solved
0 Replies
201 Views
I have a browser based web app that I would like to save private data onto the ios device's keychain. This data is a long json string. Is it possible to use keychain as the destination and preferably with face/touch id?
Posted
by dharric.
Last updated
.
Post not yet marked as solved
0 Replies
614 Views
I am currently using the WKWebView to evaluate Javascript in my Swift code. This code uses the callAsyncJavaScript to evaluate Javascript. My code takes parameters from the user and then injects those parameters into the Javascript string that is evaluated by callAsyncJavaScript. This of course is an opportunity for js injection attacks that could cause unwanted js to run. I know Apple uses WebViews in their own native apps like Music. But there is nowhere I can find best practices on how to prevent js injection attacks. Anyone have experience with this? Here's a sample function I use. func createMessage(message: ARMessageDto) async -> ArweaveResult {     do {       guard self.walletStr != nil && !self.walletStr!.isEmpty else {         return Result.failure(TransactionError.General("No wallet exists for this user"))       }       let balance = try await self.arweaveQuerySvc.getBalance()       if balance < 1_000_000_000_000 {         return Result.failure(TransactionError.General("Error wallet balance is less than 1,000,000,000,000 Winston"))       }       guard case .none = message.validate() else {         return Result.failure(TransactionError.ParametersInvalid(message.validate()))       }               let respondingToTransId = message.respondingToTransId ?? ""       let result = try await self.webView!.callAsyncJavaScript("""             \(baseScript!)             const arweaveSvc = main('\(walletStr!)');             const result = await arweaveSvc.createMessage(               '\(message.msg)',               \"\(message.userName)\",               \"\(respondingToTransId)\"             );             return result;           """, contentWorld: WKContentWorld.defaultClient)       _ = await self.arweaveQuerySvc.mine()       return try getTransactionResult(result: result)     } catch {       return Result.failure(TransactionError.General("Failed to create profile"))     }   }
Posted
by dharric.
Last updated
.
Post marked as solved
1 Replies
414 Views
I need the javascript capabilities that are not provided by JavaScriptCore like fetch and npm, but don't need any UI. Is it possible to make it not visible or at least extremely tiny? I've tried frame .zero and CGRect all zero but it's still fully visible.
Posted
by dharric.
Last updated
.
Post not yet marked as solved
0 Replies
711 Views
I have a wkwebview that loads an html file. That file also has script tags for multiple scripts that get loaded as modules. I am trying to run some of the functions inside those modules using evaluateJavaScript, but I cannot either import the respective module or call any of my objects or functions inside the modules. If I create a new function and try running it from evaluateJavaScript that does work. The errors are like "Can't find variable" or "import expects exactly one argument". What am I missing?
Posted
by dharric.
Last updated
.
Post marked as solved
2 Replies
1.9k Views
I am writing some integration tests and I want to load a file as a Data object. I keep getting the error "couldn't be opened because there is no such file". This is with the file in the same folder as the test class. I also tried creating a new asset catalog into the same project as the test but it also does not work. Here's a few attempts that did not work. let fileUrl = URL(fileURLWithPath: "\(FileManager.default.currentDirectoryPath)media.png")     let mediaFile = try Data(contentsOf: fileUrl) let fileUrl = URL(fileURLWithPath: FileManager.default.currentDirectoryPath).appendingPathComponent("media.png") let mediaFile = try Data(contentsOf: fileUrl)
Posted
by dharric.
Last updated
.
Post not yet marked as solved
0 Replies
514 Views
I am able to find many other elements like buttons and scrollViews, but not any Stack element like ZStack or VStack. These stacks are just acting as containers, not as buttons or some other interaction. I've also tried using otherElements and collectionViews, but nothing seems to work. Anyone know?
Posted
by dharric.
Last updated
.
Post not yet marked as solved
0 Replies
281 Views
At first I thought this was a bug in my code, but now I think this is just normal behavior in the sense of the re-render order. So what I noticed is that when my Button, who's action is set to run withAnimation to set a show property toggle, is clicked the immediate behavior is for re-render to run and then the toggle to actually happen. In other words simply triggering withAnimation to run is causing a re-render to happen. Other than moving my View into the same parent that my Button lives in, is there some other method to make this work? Perhaps not using withAnimation and doing animations with .animation modifier?
Posted
by dharric.
Last updated
.
Post not yet marked as solved
0 Replies
271 Views
I have a ZStack with a View inside of it that only takes up around 75% of the ZStack space. I would like to make it so that when a user taps on the ZStack outside of the child View the app executes something. In other words tapping the child View should do nothing. So far I've tried setting the ZStack's onTapGesture so that my code runs there, but of course this engages no matter where I tap, even when tapping on child. I saw the contentShape but it seems to only handle an entire shape. I would need to basically put a hole in it to work. Anyone doing this?
Posted
by dharric.
Last updated
.
Post not yet marked as solved
1 Replies
469 Views
I have an Image that I use foregroundColor on to modify it. Of course once it's modified it no longer is a plain Image. So then my struct init, that expects an Image parameter, requires that the modified Image get cast into an Image again. And this is what the XCode compiler recommends as well. However when I do that and run it it exceptions with: Could not cast value of type 'SwiftUI.ModifiedContent<SwiftUI.Image, SwiftUI._EnvironmentKeyWritingModifier<Swift.Optional<SwiftUI.Color>>>' (0x132846fa0) to 'SwiftUI.Image' Here's some code. struct PostButton: View {   @EnvironmentObject var env: EnvironmentVM       var body: some View {     let primaryImage = Image(systemName: "plus.message").foregroundColor(getIconColor(env.darkMode.isOn)) as! Image     let cameraImage = Image(systemName: "plus.message").foregroundColor(getIconColor(env.darkMode.isOn)) as! Image     let messageImage = Image(systemName: "plus.message").foregroundColor(getIconColor(env.darkMode.isOn)) as! Image           ExpandingButtonPanel(primaryButton: ExpandingButton(label: primaryImage), secondaryButtons: [       ExpandingButton(label: cameraImage),       ExpandingButton(label: messageImage)     ])   } } struct ExpandingButton: Identifiable {   let id = UUID()   let label: Image   let action: (() -> Void)? = nil } struct ExpandingButtonPanel: View {   @EnvironmentObject var env: EnvironmentVM   @StateObject var vm: PostVM = PostVM()   let primaryButton: ExpandingButton   let secondaryButtons: [ExpandingButton]
Posted
by dharric.
Last updated
.
Post not yet marked as solved
1 Replies
346 Views
I have this very simple code below and I am using the currentMenu to set the current tab's proper icon. But neither the button action nor the onTapGesture are executing as I see no print messages at all. It seems taps inside of tabItem are not registering. NavigationView { } .tabItem { Button { print("chat tapped") env.currentMenu = DeChatMenus.PrivateDM } label: { Image(env.currentMenu == DeChatMenus.PrivateDM ? "Chat.Sel" : "Chat") } } .tag(DeChatMenus.PrivateDM)
Posted
by dharric.
Last updated
.
Post not yet marked as solved
3 Replies
1.8k Views
I have an @EnvironmentObject, store, I need to pass the variable as a parameter to my @StateObject's, vm, initializer. I first tried the View's init but an @EnvironmentObject is not yet existing upon View init. So then I tried the onAppear but onAppear does not allow use of self. Is this even possible? For reference I've included both the init and the onAppear, neither works.   @EnvironmentObject var store: Store   @StateObject private var vm: NewsViewModel       init() {     self._vm = StateObject(wrappedValue: NewsViewModel(self._store.wrappedValue.newsApi))   }           var body: some View {     if vm.show == true {       HStack {         Image("round-flag")           .resizable()           .aspectRatio(contentMode: .fit)           .frame(width: 20)           .rotationEffect(.degrees(-28))                   Text(self.vm.news?.subject ?? "")           .instaStylePrimary()                   Button {           vm.show = false         } label: {           Image(systemName: "xmark")             .instaStylePrimary()             .frame(width: 12)             .foregroundColor(.gray)         }       }     }   } }
Posted
by dharric.
Last updated
.
Post not yet marked as solved
0 Replies
348 Views
I downloaded Oleo Script from Google and would like to use it in my iOS project. I've tried copying it into a folder on my main project and then adding it to info.plist via the Fonts provided by application Item 0 entry. However when I run this code to see the font family name it does not show up in the list. I've also tried various names to add it to my Text view but it did not work.    // get each of the font families    for family in UIFont.familyNames.sorted() {     let names = UIFont.fontNames(forFamilyName: family)     // print array of names     print("Family: \(family) Font names: \(names)")    }   }
Posted
by dharric.
Last updated
.