Swift Packages

RSS for tag

Create reusable code, organize it in a lightweight way, and share it across Xcode projects and with other developers using Swift Packages.

Posts under Swift Packages tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

How to Use RealityKitContent Package for App Targets Lower Than iOS 18.0
I am trying to display a 3D model in iOS app using RealityView. The same 3D model is displayed successfully in the visionOS app. Everything works perfectly only when I set my project’s minimum deployment target to iOS 18.0. However, my app’s minimum deployment target is iOS 15.0. When I use the RealityKitContent package to load the 3D model, it fails to compile and gives me the following error: Compiling for iOS 15.0, but module 'RealityKitContent' has a minimum deployment target of iOS 18.0: /Users/Library/Developer/Xcode/DerivedData/RealityViewForiOS-cbfkgimsqngtuegqwvezusvscllf/Index.noindex/Build/Products/Debug-iphonesimulator/RealityKitContent.swiftmodule/arm64-apple-ios-simulator.swiftmodule I have made the RealityKitContent package optional and tried importing using the following condition: #if canImport(RealityKitContent) import RealityKitContent #endif Despite this, it still fails to compile and produces the same error. I have not found a workaround for using the RealityKitContent package with app targets lower than iOS 18.0. Here is my package definition: let package = Package( name: "RealityKitContent", platforms: [ .visionOS(.v1), .macOS(.v15), .iOS(.v18) ], products: [ .library( name: "RealityKitContent", targets: ["RealityKitContent"]), ], dependencies: [], targets: [ .target( name: "RealityKitContent", dependencies: []), ] ) Here is the code I am using to load the 3D model with RealityView using the RealityKitContent package: import SwiftUI import RealityKit #if canImport(RealityKitContent) import RealityKitContent #endif struct ContentView: View { var body: some View { VStack { if #available(iOS 18.0, *) { RealityView { content in if let scene = try? await Entity(named: "Scene", in: realityKitContentBundle) { content.add(scene) } } update: { content in if let scene = content.entities.first { let uniformScale: Float = 3.0 scene.transform.scale = [uniformScale, uniformScale, uniformScale] } } } else { // Fallback for earlier versions } } } } #Preview { ContentView() } Any help or guidance on how to use the RealityKitContent package for app targets lower than iOS 18.0 would be greatly appreciated.
0
2
409
Jul ’24
Linker errors when building with Xcode 15 and CocoaPods — building for iOS
** BUILD FAILED ** The following build commands failed: Ld /Users/siddesh/Library/Developer/Xcode/DerivedData/App-ddpkkzvberburtewkcvoihnirgjh/Build/Intermediates.noindex/Pods.build/Release-iphonesimulator/Logging.build/Objects-normal/x86_64/Binary/Logging normal x86_64 (in target 'Logging' from project 'Pods') (1 failure) Testing with xcodebuild. -> mySDK_Staging (8.8.0) - WARN | attributes: Missing required attribute license. - WARN | license: Missing license type. - WARN | source: Git SSH URLs will NOT work for people behind firewalls configured to only allow HTTP, therefore HTTPS is preferred. - WARN | [iOS] license: Unable to find a license file - ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. - NOTE | xcodebuild: note: Using codesigning identity override: - - NOTE | [iOS] xcodebuild: note: Building targets in dependency order - NOTE | [iOS] xcodebuild: note: Target dependency graph (20 targets)
0
0
261
Jul ’24
Linker errors when building with Xcode 12 and CocoaPods — building for iOS
** BUILD FAILED ** The following build commands failed: Ld /Users/siddesh/Library/Developer/Xcode/DerivedData/App-ddpkkzvberburtewkcvoihnirgjh/Build/Intermediates.noindex/Pods.build/Release-iphonesimulator/Logging.build/Objects-normal/x86_64/Binary/Logging normal x86_64 (in target 'Logging' from project 'Pods') (1 failure) Testing with xcodebuild. -> mySDK_Staging (8.8.0) - WARN | attributes: Missing required attribute license. - WARN | license: Missing license type. - WARN | source: Git SSH URLs will NOT work for people behind firewalls configured to only allow HTTP, therefore HTTPS is preferred. - WARN | [iOS] license: Unable to find a license file - ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. - NOTE | xcodebuild: note: Using codesigning identity override: - - NOTE | [iOS] xcodebuild: note: Building targets in dependency order - NOTE | [iOS] xcodebuild: note: Target dependency graph (20 targets)
0
0
247
Jul ’24
Watch app does not recognise package dependencies
Hello All, I'm new to the forum and learning app development. I have managed to solve most issues through the web but this one has me stumped. I'm using Xcode 15.4 on a MacBook Air M1 and working on a iOS/WatchOS project. The iOS app is done and I've started on the Watch one by copying the code over. There were 3 issues 2 of which were easy to fix but the 3rd is weird. The two dependencies I added via the SPM give a "No such module '***'" error. Any ideas anybody? Yours hopefully, Michael
0
0
245
Jul ’24
Problems with SwiftUI preview and packages
My project has an iOS and WatchOS app. I added a package dependency, which supports both iOS and WatchOS, though I have only added the library to my iOS app. I can compile and run both apps just fine but when I try to use one of the WatchOS app views in Canvas preview I get errors saying different properties defined in the packages files are not available on watchOS. These blocks of code that give errors are wrapped in: "if TARGET_OS_IPHONE". I have selected the Watch Target and a watch device in the run selector as well as in the canvas. Why is this failing and how can I get it working? Thanks
0
0
362
Jul ’24
Text .onTapGesture Never Called When Shown with .onLongPressGesture
I'm showing a Text View when a button with an image is long-pressed. import SwiftUI struct ContentView: View { @Environment(\.colorScheme) var colorScheme var isDark: Bool { return colorScheme == .dark } @State private var showLabel = false var body: some View { Button(action: { }) { VStack { ZStack { Image(systemName: "swift") .resizable() .aspectRatio(contentMode: .fit) .frame(width: 32) .padding(.horizontal, 40) .padding(.vertical, 6) .background(.gray.opacity(0.2), in: RoundedRectangle(cornerRadius: 10)) .onTapGesture { showLabel.toggle() } .onLongPressGesture(minimumDuration: 2) { print("Long pressed...") showLabel.toggle() } if showLabel { Text("Help Content") .font(.caption) .foregroundStyle(!isDark ? .white : .black) .padding(10) .background(!isDark ? .black : .white, in: Rectangle()) .onTapGesture { print("hey") showLabel.toggle() } .offset(x: 120) } } } } } } So a Text View will appear as shown in the image above. But its .onTapGesture is never called. I wonder why? Thanks.
1
0
392
Jul ’24
Opting into dark mode does not get picked up by app update
Our app has previously not supported dark mode and we had the "Appearance" entry in our Info.plist set to "Light". We are now about to release an update that enables dark mode support. To enable this we have: Added a preference to our app's settings screen that lets users choose between System, Light and Dark options. Based on the user's preference, we set the entire app's preferred color scheme using the SwiftUI .preferedColorScheme modifier on our root view. Removed the "Appearance" entry from our Info.plist This is all tested and working in our local development builds. We are now testing out the app for release using an internal TestFlight build and we've run into a problem - after initially updating the app, it does not seem to detect the change to the Info.plist and the app remains in light mode even if you change the preferred colour scheme. If you force quite the app from the app switched and re-launch it, the colour scheme preference starts working as expected. This is going to be an issue for our users because when they update the app it is going to look like the new color scheme setting does not work. Having to ask customers to force quit the app from the app switcher is not really an acceptable workaround. I'm not sure this is specifically tied to the app process being killed because I would expect that to happen anyway when the app is updated. I'm wondering if this is related to the system caching the UISceneSession for the app and the act of force killing it from the app switcher is what causes the cached session to be created. Is this a known issue and is there any way to solve this?
2
0
458
Jul ’24
Failure Reason: The request was denied by service delegate (SBMainWorkspace).
Hi, I have developed application in flutter. build is successfull but when I am getting below error when I am trying to install app on my phone through Xcode. Xcode Version 15.4 (15F31d). The request to open "com.hl240n.vast" failed. Domain: IDELaunchCoreDevice Code: 0 User Info: { DVTErrorCreationDateKey = "2024-07-16 13:54:17 +0000"; IDERunOperationFailingWorker = IDELaunchCoreDeviceWorker; } The request to open "com.hl240n.vast" failed. Domain: IDELaunchCoreDevice Code: 0 User Info: { IDERunOperationFailingWorker = IDELaunchCoreDeviceWorker; } The application failed to launch. Domain: com.apple.dt.CoreDeviceError Code: 10002 User Info: { BundleIdentifier = "com.hl240n.vast"; } The request to open "com.hl240n.vast" failed. Domain: FBSOpenApplicationServiceErrorDomain Code: 1 Failure Reason: The request was denied by service delegate (SBMainWorkspace). User Info: { BSErrorCodeDescription = RequestDenied; FBSOpenApplicationRequestID = 0xc417; } The operation couldn’t be completed. The process failed to launch. Domain: FBProcessExit Code: 64 Failure Reason: The process failed to launch. User Info: { BSErrorCodeDescription = "launch-failed"; } The operation couldn’t be completed. Launch failed. Domain: RBSRequestErrorDomain Code: 5 Failure Reason: Launch failed. Launchd job spawn failed Domain: NSPOSIXErrorDomain Code: 85 Failure Reason: Bad executable (or shared library) Event Metadata: com.apple.dt.IDERunOperationWorkerFinished : { "device_isCoreDevice" = 1; "device_model" = "iPhone13,2"; "device_osBuild" = "17.5.1 (21F90)"; "device_platform" = "com.apple.platform.iphoneos"; "dvt_coredevice_version" = "355.28"; "dvt_mobiledevice_version" = "1643.120.2"; "launchSession_schemeCommand" = Run; "launchSession_state" = 1; "launchSession_targetArch" = arm64; "operation_duration_ms" = 3951; "operation_errorCode" = 0; "operation_errorDomain" = IDELaunchCoreDevice; "operation_errorWorker" = IDELaunchCoreDeviceWorker; "operation_name" = IDERunOperationWorkerGroup; "param_debugger_attachToExtensions" = 0; "param_debugger_attachToXPC" = 1; "param_debugger_type" = 3; "param_destination_isProxy" = 0; "param_destination_platform" = "com.apple.platform.iphoneos"; "param_diag_MainThreadChecker_stopOnIssue" = 0; "param_diag_MallocStackLogging_enableDuringAttach" = 0; "param_diag_MallocStackLogging_enableForXPC" = 1; "param_diag_allowLocationSimulation" = 1; "param_diag_checker_tpc_enable" = 1; "param_diag_gpu_frameCapture_enable" = 0; "param_diag_gpu_shaderValidation_enable" = 0; "param_diag_gpu_validation_enable" = 0; "param_diag_memoryGraphOnResourceException" = 0; "param_diag_queueDebugging_enable" = 1; "param_diag_runtimeProfile_generate" = 0; "param_diag_sanitizer_asan_enable" = 0; "param_diag_sanitizer_tsan_enable" = 0; "param_diag_sanitizer_tsan_stopOnIssue" = 0; "param_diag_sanitizer_ubsan_stopOnIssue" = 0; "param_diag_showNonLocalizedStrings" = 0; "param_diag_viewDebugging_enabled" = 1; "param_diag_viewDebugging_insertDylibOnLaunch" = 1; "param_install_style" = 0; "param_launcher_UID" = 2; "param_launcher_allowDeviceSensorReplayData" = 0; "param_launcher_kind" = 0; "param_launcher_style" = 99; "param_launcher_substyle" = 8192; "param_runnable_appExtensionHostRunMode" = 0; "param_runnable_productType" = "com.apple.product-type.application"; "param_structuredConsoleMode" = 1; "param_testing_launchedForTesting" = 0; "param_testing_suppressSimulatorApp" = 0; "param_testing_usingCLI" = 0; "sdk_canonicalName" = "iphoneos17.5"; "sdk_osVersion" = "17.5"; "sdk_variant" = iphoneos; } System Information macOS Version 14.5 (Build 23F79) Xcode 15.4 (22622) (Build 15F31d) Timestamp: 2024-07-16T19:24:17+05:30 Thanks, Hari
1
0
445
Jul ’24
Attach a Attachment to the hand VisionOS
I am trying to attach a button to user's left hand. the position is tracked. the button stays above the user's left hand. but it doesn't face the user. or it doesn't even face where the wrist is pointing. this is the main code snippet: if (model.editWindowAdded) { let originalMatrix = model.originFromWristLeft let theattachment = attachments.entity(for: "sample")! entityDummy.addChild(theattachment) let testrotvalue = simd_quatf(real: 0.9906431, imag: SIMD3<Float>(-0.028681312, entityDummy.orientation.imag.y, 0.025926698)) entityDummy.orientation = testrotvalue theattachment.position = [0, 0.1, 0] var timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) {_ in let originalMatrix = model.originFromWristLeft print(originalMatrix.columns.0.y) let testrotvalue = simd_quatf(real: 0.9906431, imag: SIMD3<Float>(-0.028681312,0.1, 0.025926698)) entityDummy.orientation = testrotvalue } }
2
0
535
Jul ’24
detecting Phone Number changed
Hello, I am involved in planning a digital ID app for the government. We are aiming to provide various personal information through this app, including the consideration of including the user's phone number. During the app installation process, we can collect the accurate user's phone number through SMS verification. However, I'm curious if there's a way for our app or server to detect when a user changes their phone number after installing the app. I understand that Apple's policies prevent us from automatically collecting the user's phone number. However, it would be beneficial if we could at least know if the phone number provided by the server differs from the current phone number on the smartphone.
3
0
387
Jul ’24
screenshot for iPhone home screen
When having my iPhone connected to my Mac via USB cable, how can I take a screenshot of the home screen from a swiftUI app? I tried using libimobiledevice (idevicescreenshot) but that requires install the developer disk image. When looking for it, it turns that my Xcode (version 15.4) only provides that kind of images up to iOS 16.4. I have looked everywhere on this site, but couldn't fine the required image or otherwise, how to take the screenshot I need. Thanks!
3
0
510
Jul ’24
swift run on Xcode 16 beta 2 for Swift Package crashes with SIGKILL Guard
With connection of SSH via Jenkins 2.332.1 to the remote Macs, swift-package module crashes and leaves crash report on Console. Absolutely swift command itself fails. Filed https://feedbackassistant.apple.com/feedback/14285692 with the crash report created. Really hard to explain what happens exactly but seems like it is related to Xcode 16 beta (xcrun version 70) because the same problem never occurs on Xcode 15.4 (xcrun version 68).
1
0
389
Jul ’24
Issues manually adding a module to my project
Hello. I'm working on the iOS native side of a react native library (don't worry this question is specifically about the iOS native part). My library relies on the GoogleSignIn library from google. The problem is it uses functionality from a fork that has not been merged by Google yet, and .podspec files do not support specifying a git repo for a module like the actual Podfile does. To circumvent this issue I opted to clone the fork into my libraries source code and treat it as a sort of submodule. I setup the public_header_files/private_header_files/resource_bundle properties in my podspec based on the GoogleSignIn submodules podspec and added the headers to my HEADER_SEARCH_PATHS. I then added the public headers to my bridging header. So in my podspec I have s.source_files = "ios/**/*.{h,m,mm,swift}", "GoogleSignIn-iOS/GoogleSignIn/Sources/**/*.{h,m,mm,swift}" s.public_header_files = "GoogleSignIn-iOS/GoogleSignIn/Sources/Public/GoogleSignIn/*.h" s.private_header_files = "GoogleSignIn-iOS/GoogleSignIn/Sources/**/*.h" s.resource_bundle = { 'GoogleSignIn' => ['GoogleSignIn-iOS/GoogleSignIn/Sources/{Resources,Strings}/*'] } s.pod_target_xcconfig = { 'HEADER_SEARCH_PATHS' => '"$(inherited)" "$(PODS_ROOT)/GoogleSignIn-iOS/GoogleSignIn/Sources/Public/GoogleSignIn" "$(PODS_ROOT)/GoogleSignIn-iOS/GoogleSignIn/Sources"' } s.user_target_xcconfig = { 'HEADER_SEARCH_PATHS' => '"$(inherited)" "$(PODS_ROOT)/GoogleSignIn-iOS/GoogleSignIn/Sources/Public/GoogleSignIn" "$(PODS_ROOT)/GoogleSignIn-iOS/GoogleSignIn/Sources"' } and in my bridging header #import "GIDAppCheckError.h" #import "GIDConfiguration.h" #import "GIDGoogleUser.h" #import "GIDProfileData.h" #import "GIDSignIn.h" #import "GIDSignInButton.h" #import "GIDSignInResult.h" #import "GIDToken.h" #import "GoogleSignIn.h" This is working to some extent because I can see the headers in my pod project Not sure why they're under project but I manually moved them to private/public and it didn't seem to affect anything. Anyway regardless which category I put the headers in, I cannot actually import GoogleSignIn from outside the "submodule". Additionally, some files within the "submodule" cannot find each other. For example at GoogleSignIn-iOS/GoogleSignIn/Sources/GIDToken.m I have #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDToken.h", which just results in 'GoogleSignIn/Sources/Public/GoogleSignIn/GIDToken.h' file not found. If I just do #import "GIDToken.h" its fine but I can't actually rewrite the imports otherwise they'll break again when I update the submodule from git. I have asked on several Discord communites as well as ChatGPT but I cannot find any configuration that makes this submodule work via the podspec.
1
0
259
Jul ’24
Swift Package with @objc cannot find interface declaration
I am using a Swift PM module and adding it to a brand new project. This project is Objective-C based, but I would like to use the module within a .swift file as I am working to migrate part of my project to Swift. The .swift file is called from the Objective-C app delegate. When doing this method on a brand new project, it builds correctly. However, when I add the module to my production app (has been in development for 10 years) in the same way, I get the following error in my MyApp-Swift.h file: Cannot find interface declaration for 'MBNavigationViewController', superclass of 'CarPlayMapViewController'; did you mean 'UINavigationController'? I have even created a stripped down version of my app with minimal files and it still does not build. There must be some build setting or something else that allows the module to work in a brand new project (accessing the MyApp-Swift.h file that generates the Obj-C methods) but not in my older project?
1
0
523
Jul ’24