Posts

Post marked as solved
1 Replies
171 Views
I am trying to display a SKScene inside a SwiftUI list but I'm having problems getting it to size properly. Here is the code I'm using: struct MyView: View { var scene: SKScene // this is a SKScene with .aspectFit scaling mode var body: some View { List { Section { GeometryReader { geo in SpriteView(scene: scene, options: [.allowTransparency]) .frame(height: geo.size.width / scene.size.width * scene.size.height) } } Section { Text("SomeOtherStuff") } } } } Doing this scales the actual SKScene properly but the list 'cell' doesn't stretch to fit the scene it contains, therefore clipping chunks of said scene. If I drop the GeometryReader and hard code the height, the cell resizes. My guess is that the SKScene dimensions are not yet available to SwiftUI when the GeometryReader is evaluated. Any suggestions?
Posted
by bbousquet.
Last updated
.
Post marked as solved
11 Replies
39k Views
My iOS app supports a document type and includes the appropriate UTI data. It can therefore open documents of a specific type from mail attachments, for instance. It works well.I am currently stumped, however: when I open a document from the iCloud Drive app (tap document, share button, "Copy to <app>") my application gets launched but any attempts to copy the item from the provided URL fails with NSCocoaErrorDomain, error 257 (basically telling me I don't have the permissions to read the file). This issue is not present when my app is running in the background, however, and does not seem to occur when the app gets launched from a mail attachment (whether it's running ot not).I compared the URLs handed to my app and they are identical, whether the app was running or not.Here's the URL my app is handed: "file:///private/var/mobile/Library/Mobile%20Documents/com~apple~CloudDocs/filename.ext"The code I'm using is the following:// uniqueURL is a destination URL in my app's sandbox: // file:///var/mobile/Containers/Data/Application/12AB2BA0-EA63-4FAC-A7D8-779964868B06/Documents/filename.ext dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { let fileCoordinator = NSFileCoordinator(filePresenter: nil) fileCoordinator.coordinateReadingItemAtURL(url, options: .WithoutChanges, error: nil) { newURL in do { try NSFileManager.defaultManager().copyItemAtURL(newURL, toURL: uniqueURL) } catch { print("Error!") // this is where I'm getting NSCocoaErrorDomain:257 } }This issue seems to be identical to that other thread:https://forums.developer.apple.com/message/29985#29985However, I'm not running on a beta OS. My device is an iPhone 6s running iOS 9.3.2 (13F69).
Posted
by bbousquet.
Last updated
.
Post not yet marked as solved
0 Replies
705 Views
I have a View that consists of a NavigationView. I set its style to .stack using .navigationViewStyle to force the 'stacked' modal look when appropriate (I am displaying it modally from UIKit using a UIHostingController). This works fine but I need the view to detect if it's actually shown using the stacked look or not at runtime (on an iPhone in landscape mode, it will be displayed as full screen and I need to add a Close/Dismiss button in that specific case). Suggestions?
Posted
by bbousquet.
Last updated
.
Post not yet marked as solved
1 Replies
703 Views
I have a UICollectionViewController in shared iOS/tvOS code. On iOS I use context menus while I fallback to UIAlertController (alert sheet) triggered by a long press on tvOS. viewDidLoad: override func viewDidLoad() {     super.viewDidLoad() // ...     #if os(tvOS)     let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction(_:))) collectionView.addGestureRecognizer(longPressGestureRecognizer)     #endif } Selector: #if os(tvOS) @objc func longPressAction(_ sender: UIGestureRecognizer) {     guard sender.state == .began else {         return     }     if let indexPath = collectionView.indexPathForItem(at: sender.location(in: collectionView)) {         let ac = UIAlertController(/* ... */) // alert sheet         present(ac, animated: true, completion: nil)     } } #endif Upon long pressing, the alert sheet gets displayed properly on tvOS but the first tap on one of the sheet actions is ignored (this calls longPressAction again with a .cancel state). I tried inserting a sender.isEnabled = false after the guard but it simply caused the .cancel state to come in faster while still eating the first tap. Suggestions?
Posted
by bbousquet.
Last updated
.
Post marked as solved
2 Replies
1.1k Views
I have a UITableViewController shared between my iOS and tvOS apps. In order to refresh some of the cells, I call reloadRows. It works fine as far as updating the cell's data but, on tvOS, it moves the focus back to the top of the table. I've noticed that preferredFocusEnvironments does not get called (unlike what happens when I do reloadData). This is pretty much the same issue mentioned in the following post (years ago): https://developer.apple.com/forums/thread/67219 Any suggestions?
Posted
by bbousquet.
Last updated
.
Post not yet marked as solved
0 Replies
1.2k Views
My iOS app needs to open data files from iCloud drive to flash some of our devices. We use .hex and .bin file extensions. I'm supplying the appropriate document types to UIDocumentPickerViewController (I have also defined them in my Info.plist's Imported UTIs section). UIDocumentPickerViewController keeps the .bin files grayed out, however. I understand that these fall under the system defined "com.apple.macbinary-archive" type. Is there any way to let the document picker mark those as available or should I just rely on renaming the file?
Posted
by bbousquet.
Last updated
.
Post marked as solved
4 Replies
7.7k Views
I've been experimenting with SwiftUI and couldn't figure out how to get a simple UIToolbar to appear at the bottom of the screen.Basic view:struct MyView : View { var body: some View { NavigationView { List { NavigationButton(destination: Text("1")) { Text("Element 1") } // ... }.navigationBarTitle(Text("Elements")) } } }
Posted
by bbousquet.
Last updated
.
Post not yet marked as solved
2 Replies
1.3k Views
I'm in the process of converting my local frameworks to local Swift packages. Things are (mostly) working well but I'm struggling with one of the packages: Package MyKit is used by an iOS and a tvOS app. It includes a storyboard for each platform. What is the most appropriate way to describe this in Package.swift? Xcode complains about iOS storyboards not being supported on tvOS so I moved them to their own targets, like this: let package = Package(     name: "MyKit",     defaultLocalization: "en",     platforms: [         .tvOS(.v13)     ],     products: [         // Products define the executables and libraries a package produces, and make them visible to other packages.         .library(             name: "MyKit",             targets: ["MyKit"]),     ],     dependencies: [         // Dependencies declare other packages that this package depends on.         // .package(url: /* package url */, from: "1.0.0"),     ],     targets: [         // Targets are the basic building blocks of a package. A target can define a module or a test suite.         // Targets can depend on other targets in this package, and on products in packages this package depends on.         .target(             name: "MyKit",             dependencies: [                 .target(name: "MyKit-iOS", condition: .when(platforms: [.iOS])),                 .target(name: "MyKit-tvOS", condition: .when(platforms: [.tvOS])),             ]),         .target(             name: "MyKit-iOS",             dependencies: []),         .target(             name: "MyKit-tvOS",             dependencies: [])     ] This builds fine but it seems clunky to me (and I'm having issues accessing the Main.storyboard file from the package itself.
Posted
by bbousquet.
Last updated
.
Post marked as solved
8 Replies
2.7k Views
Dabbling with Network.framework to see if I can replace some old socket based code on iOS. I was able to establish a TCP connection and send/receive data but I'm puzzled as to how receive timeouts should be handled: I can code my own timeouts using GCD but there doesn't seem to be a way to actually cancel the pending receive (it does seem to timeout by itself after a minute or so, tearing down the NWConnection with it - definitely not what I'm looking for).Any suggestions?
Posted
by bbousquet.
Last updated
.