Dive into the world of programming languages used for app development.

All subtopics

Post

Replies

Boosts

Views

Activity

Swift Student Challenge
Hi, I stumbled about the Swift Student Challenge at Apples Website and now I have some questions. I've programmed some Apps in Xcode and I think one of them might be pretty god for this Challenge. Now I've read something about Swift Playgrounds and I'm confused. What's a Swift Playground? Do I need to create one or is it enough to have the App? and finally: I'm currently 14 and live in Germany. Is it possible to participate when I'm 14? And if not would it be a big thing to lets say forget my age and somehow think that I'm 16? Thanks a lot for answers
3
0
885
Jan ’24
Change in URL redirect in iOS 17.2?
My app uses 2FA as part of its login process. The 2FA system sends a URL callback to the app when it completes indicating success or failure. Suddenly, on devices running iOS 17.2, the behavior surrounding this callback has changed. The URL callback is received by the AppDelegate's application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) method, and in iOS 17.1 and previous that happened whether the app was in the foreground or background. On iOS 17.2, however, that method only gets called if the app is in the foreground. If it is in the background it is not called and a message is output to the console containing this error: Failed to open URL [2FA callback url]. The request to open [app bundle id] failed. The request was denied by service delegate (SBMainWorkspace) for reason: Security ("Application [app bundle id] is neither visible nor entitled, so may not perform un-trusted user actions"). Since most users background the app to open the 2FA app, this is the more likely scenario. The 2FA callback URL is listed in URL Types in Project Info. Is there some step I need to make the app entitled to receive the 2FA callback?
0
1
639
Jan ’24
Swift Playgrounds lessons not showing Swift 5.9
Hey folks! I remember some weeks/months ago to get some lessons with updated Swift 5.9, I'm just not sure if this happened while I was using Swift Playgrounds beta from TestFlight. Anyways, I went back to study using Swift Playgrounds and all the lessons are using Swift 5.8 here. I don't know what happened or how can I have the lessons updated again. Anyone else noticed this issue? Any tip on how to solve it?
7
0
1.2k
Jan ’24
How to prevent initial rotation of a node when following a UIBezierPath?
Problem = I have a locomotive trying to follow an oval-shaped UIBezierPath. The challenge is that when I use orientToPath:true in my call to SKAction.follow, the locomotive immediately rotates even though the locomotive is initially positioned on the straight portion of the oval before it reaches the rounded portion of the oval. If I could prevent this initial rotation, then the rotation would not happen until it reached the rounded portion of the oval - as it should. So, can you please provide some guidance as to how I could prevent this initial rotation? Here is the code: func createTrainPath() { // this custom method ensures that the locomotive // moves CW, versus CCW trackPath = getBezierPath(theNode: myTrain, offset: 0.0) } // createTrainPath func startFollowTrainPath() { let theSpeed = Double(5*thisSpeed) var trainAction = SKAction.follow( trackPath.cgPath, asOffset: true, orientToPath: true, // <== speed: theSpeed) trainAction = SKAction.repeatForever(trainAction) myTrain.run(trainAction, withKey: runTrainKey) } // startFollowTrainPath
3
0
604
Jan ’24
SwiftData Crashes When Using Custom Migration.
I have 2 vesrion schema and Migration plan. Version 2: Add new properties and Property renamed. static let release: ModelContainer = { do { let schema = Schema(versionedSchema: V2Schema.self) let appGroupURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "***") let databaseURL = appGroupURL?.appending(path: "Models.sqlite") let databaseName = "Models" let configuration = ModelConfiguration(databaseName, schema: schema, url: databaseURL!, cloudKitDatabase: .automatic) return try ModelContainer(for: schema, migrationPlan: ModelMigrationPlan.self, configurations: [configuration]) } catch { fatalError(error.localizedDescription) } }() enum ModelMigrationPlan: SchemaMigrationPlan { static var schemas: [VersionedSchema.Type] { [V1Schema.self, V2Schema.self] } static var stages: [MigrationStage] { [v1ToV2MigrationStage] } } When I test migration in UnitTest, It works fine. But In running in device, error is occurred. error: Store failed to load. <NSPersistentStoreDescription: 0x1077aa330> (type: SQLite, url: file:///private/var/mobile/Containers/Shared/AppGroup/***/Model.sqlite) with error = Error Domain=NSCocoaErrorDomain Code=134504 "Cannot use staged migration with an unknown model version." UserInfo={NSLocalizedDescription=Cannot use staged migration with an unknown model version.} with userInfo { NSLocalizedDescription = "Cannot use staged migration with an unknown model version."; } Has anyone experienced this same problem or know a solution?
4
0
875
Jan ’24
Strange visionOS Simulator
I found that my visionOS Simulator is very strange. Many functions and features are missing. For example, I learned from the Internet that the immersive scenes of Environments in their visionOS Simulator can be opened, but I click There was no response after the attack. There are not only these, but also many system features. I saw on the Internet that other developers have them, and I am missing. I'm worried that this will have an impact on me when testing my app. May I ask why? Some information: My updated Xcode version is the latest Xcode15.1Beta. Device: iMac (2021) Simulator system number: 21N305
1
0
563
Jan ’24
NWConnection, how to catch error?
I have a NWConnection, that if an invalid (ip/port), is entered, I get in debug the error: nw_socket_handle_socket_event [C1.1.1:1] Socket SO_ERROR 61. But I can't seem to trap that error. I have as my stateChangeHandler: I am creating my connection: let tcpOptions = NWProtocolTCP.Options() tcpOptions.enableKeepalive = true tcpOptions.keepaliveIdle = 2 tcpOptions.keepaliveCount = 2 tcpOptions.keepaliveInterval = 2 let params = NWParameters(tls: nil, tcp: tcpOptions) nwConnection:NWConnection(host: NWEndpoint.Host(host), port: NWEndpoint.Port(port)!, using: params). (with known nonexistent ip/port). I was hopping when I did a .start(), I would get an error in my state handler: // =============================================================================== func stateDidChange(to state: NWConnection.State) { Swift.print("State change") switch state { case .waiting(let error): print("Client waiting") connectionDidFail(error: error) case .ready: print("Client connection ready") case .failed(let error): print("Client failed") connectionDidFail(error: error) case .preparing: print("client preparing") case .setup: print("client setup") case .cancelled: print("client cancelled") default: print("Client unknown") break } } But it doesn't trap an error. So, where is this error coming from (I know the cause), but I want to trap it (in case a user puts in a wrong ip/port)
4
0
1k
Jan ’24
Unable to consistently detect lock/unlock events with Swift
I need to detect lock & unlock events in my swift iOS application. I have tried using AppDelegate functions like UIApplicationProtectedDataWillBecomeUnavailable & UIApplicationProtectedDataDidBecomeAvailable to record the lock and unlock events respectively, but have found this to be inconsistent. UIApplicationProtectedDataWillBecomeUnavailable is not called immediately after the lock event, and sometimes misses the event altogether. Is there a different approach to this problem that guarantees detecting lock & unlock correctly every time?
2
0
772
Jan ’24
OpenAPI Swift Generator
Hello, I'm using the generator to create a client from this API: https://github.com/griptape-ai/griptape-cloud-control-plane/blob/main/models/Griptape.openapi.json Everything seems fine until I go to call a method. I get an error on a DateTime format mismatch in the response. Client error - cause description: 'Unknown', underlying error: DecodingError: dataCorrupted - at : Expected date string to be ISO8601-formatted. (underlying error: <nil>), Is there a decoder option or something I can attach to the generated client code to adjust for this?
2
0
698
Jan ’24
How do you make lines of code only for a specific destination in Xcode?
Hi! I am trying to create an iOS application but also for visionOS. In the target settings, I have iPhone and Vision Pro added under the supported destinations. The problem that I am running into is that the Firebase messaging and the user notifications are not supported with Vision Pro. Is there anyway to just make those lines of code only for the iOS supported destination? If you could help, that would be greatly appreciated!
1
0
441
Jan ’24
Swift Playground Bundle can't find Compiled CoreML Model (.mlmodelc)
I have been attempting to debug this for over 10 hours... I am working on implementing Apple's MobileNetV2 CoreML model into a Swift Playgrounds. I performed the following steps Compiled CoreML model in regular Xcode project Moved Compiled CoreML (MobileNetV2.mlmodelc) model to Resources folder of Swift Playground Copy Paste the model class (MobileNetV2.swift) into the Sources folder of Swift Playground Use UIImage extensions to resize and convert UIImage into CVbuffer Implement basic code to run the model. However, every time I run this, it keeps giving me this error: MobileNetV2.swift:100: Fatal error: Unexpectedly found nil while unwrapping an Optional value From the automatically generated model class function: /// URL of model assuming it was installed in the same bundle as this class class var urlOfModelInThisBundle : URL { let bundle = Bundle(for: self) return bundle.url(forResource: "MobileNetV2", withExtension:"mlmodelc")! } The model builds perfectly, this is my contentView Code: import SwiftUI struct ContentView: View { func test() -> String{ // 1. Load the image from the 'Resources' folder. let newImage = UIImage(named: "img") // 2. Resize the image to the required input dimension of the Core ML model // Method from UIImage+Extension.swift let newSize = CGSize(width: 224, height: 224) guard let resizedImage = newImage?.resizeImageTo(size: newSize) else { fatalError("⚠️ The image could not be found or resized.") } // 3. Convert the resized image to CVPixelBuffer as it is the required input // type of the Core ML model. Method from UIImage+Extension.swift guard let convertedImage = resizedImage.convertToBuffer() else { fatalError("⚠️ The image could not be converted to CVPixelBugger") } // 1. Create the ML model instance from the model class in the 'Sources' folder let mlModel = MobileNetV2() // 2. Get the prediction output guard let prediction = try? mlModel.prediction(image: convertedImage) else { fatalError("⚠️ The model could not return a prediction") } // 3. Checking the results of the prediction let mostLikelyImageCategory = prediction.classLabel let probabilityOfEachCategory = prediction.classLabelProbs var highestProbability: Double { let probabilty = probabilityOfEachCategory[mostLikelyImageCategory] ?? 0.0 let roundedProbability = (probabilty * 100).rounded(.toNearestOrEven) return roundedProbability } return("\(mostLikelyImageCategory): \(highestProbability)%") } var body: some View { VStack { let _ = print(test()) Image(systemName: "globe") .imageScale(.large) .foregroundColor(.accentColor) Text("Hello, world!") Image(uiImage: UIImage(named: "img")!) } } } Upon printing my bundle contents, I get these: ["_CodeSignature", "metadata.json", "__PlaceholderAppIcon76x76@2x~ipad.png", "Info.plist", "__PlaceholderAppIcon60x60@2x.png", "coremldata.bin", "{App Name}", "PkgInfo", "Assets.car", "embedded.mobileprovision"] Anything would help 🙏 For additional reference, here are my UIImage extensions in ExtImage.swift: //Huge thanks to @mprecke on github for these UIImage extension function. import Foundation import UIKit extension UIImage { func resizeImageTo(size: CGSize) -> UIImage? { UIGraphicsBeginImageContextWithOptions(size, false, 0.0) self.draw(in: CGRect(origin: CGPoint.zero, size: size)) let resizedImage = UIGraphicsGetImageFromCurrentImageContext()! UIGraphicsEndImageContext() return resizedImage } func convertToBuffer() -> CVPixelBuffer? { let attributes = [ kCVPixelBufferCGImageCompatibilityKey: kCFBooleanTrue, kCVPixelBufferCGBitmapContextCompatibilityKey: kCFBooleanTrue ] as CFDictionary var pixelBuffer: CVPixelBuffer? let status = CVPixelBufferCreate( kCFAllocatorDefault, Int(self.size.width), Int(self.size.height), kCVPixelFormatType_32ARGB, attributes, &pixelBuffer) guard (status == kCVReturnSuccess) else { return nil } CVPixelBufferLockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0)) let pixelData = CVPixelBufferGetBaseAddress(pixelBuffer!) let rgbColorSpace = CGColorSpaceCreateDeviceRGB() let context = CGContext( data: pixelData, width: Int(self.size.width), height: Int(self.size.height), bitsPerComponent: 8, bytesPerRow: CVPixelBufferGetBytesPerRow(pixelBuffer!), space: rgbColorSpace, bitmapInfo: CGImageAlphaInfo.noneSkipFirst.rawValue) context?.translateBy(x: 0, y: self.size.height) context?.scaleBy(x: 1.0, y: -1.0) UIGraphicsPushContext(context!) self.draw(in: CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height)) UIGraphicsPopContext() CVPixelBufferUnlockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0)) return pixelBuffer } }
5
1
2.1k
Jan ’24
Xcode 14.3.1 Type Y has no member x
Hi, We are using Github actions to build our CI/CD. In github actions the highest xcode version possible to use 14.3.1. When trying to build the app using fastlane we encounter several errors Type 'Circle' has no member 'circle' Type 'Shape' has no member 'capsule' When looking at the documentation for circle and capsule both are @available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) capsule @available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) extension Shape where Self == Capsule { /// A capsule shape aligned inside the frame of the view containing it. /// /// A capsule shape is equivalent to a rounded rectangle where the corner /// radius is chosen as half the length of the rectangle's smallest edge. public static var capsule: Capsule { get } /// A capsule shape aligned inside the frame of the view containing it. /// /// A capsule shape is equivalent to a rounded rectangle where the corner /// radius is chosen as half the length of the rectangle's smallest edge. public static func capsule(style: RoundedCornerStyle) -> Self } circle @available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) extension Shape where Self == Circle { /// A circle centered on the frame of the view containing it. /// /// The circle's radius equals half the length of the frame rectangle's /// smallest edge. public static var circle: Circle { get } } Does anyone have any idea why would an xcode 14.3.1 and iOS 13.0 available syntax is causing this error? Thanks
0
1
324
Jan ’24
Flutter MSAL SSO with webview
Hi, I am using flutter MSAL SSO with flutter_inappwebview and azure_flutter_authentication package to login to the app. let viewController: UIViewController = UIViewController.keyViewController! let webviewParameters = MSALWebviewParameters(authPresentationViewController: viewController) webviewParameters.webviewType = .default I am trying to open another application in webview by using flutter_inappwebview, so that there will be a silent log in using MSAL SSO option in iOS device. But its not working InAppWebView( key: webViewKey, initialUrlRequest: URLRequest(url: Uri.parse(widget.url)), initialOptions: options, pullToRefreshController: pullToRefreshController, onWebViewCreated: (controller) { webViewController = controller; }, onLoadStart: (controller, url) { logger.d("printing webview controller type: " + controller.runtimeType.toString()); setState(() { this.url = url.toString(); urlController.text = this.url; isLoading = false; }); }, androidOnPermissionRequest: (controller, origin, resources) async { return PermissionRequestResponse( resources: resources, action: PermissionRequestResponseAction.GRANT); }, shouldOverrideUrlLoading: (controller, navigationAction) async { var uri = navigationAction.request.url!; if (![ "http", "https", "file", "chrome", "data", "javascript", "about" ].contains(uri.scheme)) { if (await canLaunch(url)) { // Launch the App await launch( url, ); // and cancel the request return NavigationActionPolicy.CANCEL; } } return NavigationActionPolicy.ALLOW; }, onLoadStop: (controller, url) async { pullToRefreshController?.endRefreshing(); setState(() { this.url = url.toString(); urlController.text = this.url; }); }, onLoadError: (controller, url, code, message) { pullToRefreshController?.endRefreshing(); }, onProgressChanged: (controller, progress) { if (progress == 100) { pullToRefreshController?.endRefreshing(); } setState(() { this.progress = progress / 100; urlController.text = this.url; }); }, onUpdateVisitedHistory: (controller, url, androidIsReload) { setState(() { this.url = url.toString(); urlController.text = this.url; }); }, onConsoleMessage: (controller, consoleMessage) { print(consoleMessage); }, ), How to should I pass the login session from swift code to inappwebview in flutter? Please help me with this. I really appreciate it. Its working fine with android devices. The problem is from iOS devices.
0
0
835
Jan ’24
Crash on launch, while in review - but no crash in Xcode or TestFlight
Hi all! My new iOS app (first one in Swift and SpriteKit, was using ObjectiveC and Cocos2D before, a few years back) - got rejected with the dreaded "We were unable to review your app as it crashed on launch.", That's especially bad news when it never ever crashed on any on our devices when testing (variety of phones, iPads and all sort of iOS) either in debug or release, before submission. So no luck repro-ing! The crashlog text file apple review team sent back, renamed as .crash, seems to open in Xcode (right click on it) when linked to the right project and seems to point in the leaderboard code fetching the local authenticated user's score. This is some code that I shamelessly copy/pasted from a StackOverflow page a few months ago, and seemed to work right away so moved-on back then, but something must be unsafe in there (sorry, bit of a rookie with Swift optionals etc). Any help would be much appreciated as this code seems to work fine in debug, without warnings or anything, and also works fine in release using TestFlight - so we simply cannot repro the apple QA issue, and we need to fix it blind! This is the function below that is crashing, right on the line that has the "{ player, _, _ in ": func sync_hiscore() { if (GKLocalPlayer.local.isAuthenticated) { if #available(iOS 14.0, *) { GKLeaderboard.loadLeaderboards( IDs: ["HatStacker_LD01"] ) { leaderboards, _ in leaderboards?[0].loadEntries( for: [GKLocalPlayer.local], timeScope: .allTime ) { player, _, _ in // &lt;&lt;&lt;&lt; !!! CRASHES HERE!! if ( player!.score &gt; player_hiscore) { player_hiscore = player!.score } } } } } } I've also attached the full crashlog if that's of any help! Many thanks all, sorry for such a Swift rookie question, but to add to the confusion this is also the first time one of our apps gets rejected for such an obvious bad crash at launch, that no one has seen during our weeks of testing! Any idea why it's only in release and only in the apple HQ/review env that we get that error? Could they have an invalid Game Center account that is confusing the "player" score fetching? Cheers, JBB HatStacker_build4.crash
5
0
2.4k
Jan ’24
Reading multi parts of a file concurrently
I have a need to read first half and second half of a file concurrently. Is there any best practices for this scenario? BTW, I did research on DispatchIO but it turned out DispatchIO is all about asynchronous operations on a single file handle; it cannot perform parallel reading. // naive approach Task { fileHandle.read(into:buffer) } Task { // seek to file size / 2 fileHandle.read(into:buffer) }
5
0
755
Jan ’24