Post

Replies

Boosts

Views

Activity

Troubles with CFBundleDocumentTypes and photos
I'm working on adding CFBundleDocumentTypes to my Info.plist so that a user can share an image from other apps on their device and have it open inside my iPhone app. I seem to be able to get this to work for sharing a single photo from the Photos app, but not for (1) multiple photos from the Photos app or (2) images from Safari. One thing that makes this difficult is that my changes to Info.plist sometimes have no effect. I can remove CFBundleDocumentTypes and still see the icon, for example. Or I can add a new accepted UTI, but it has no effect. I've tried cleaning and rebuilding, deleting and reinstalling the app...no success. I tried in the simulator, too, and even Erase Content and Settings didn't force changes to be applied. I'm not sure what else to try here. Anyway, I'd like my app to appear in the Share sheet for photo(s) from the Photos app, Mail and Safari, in particular, but really from any app that supports sharing photos. I can share the config that seemed to work, but since changing it doesn't always have an effect, I can't guarantee that this was the one that worked. At the moment, it doesn't work, but I'm not sure why. Here it is: <key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeIconFiles</key> <array/> <key>CFBundleTypeName</key> <string>Image</string> <key>CFBundleTypeRole</key> <string>Viewer</string> <key>LSHandlerRank</key> <string>Alternate</string> <key>LSItemContentTypes</key> <array> <string>public.data</string> <string>public.jpeg</string> <string>public.png</string> <string>public.image</string> <string>public.gif</string> <string>public.url</string> <string>public.content</string> </array> </dict> </array> <key>LSSupportsOpeningDocumentsInPlace</key> <true/> In my code, I also defined the following method in my SceneDelegate (though I think the problem is just with Info.plist): func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { Here are my questions: How do I make sure that my changes to Info.plist apply? Is there a cache somewhere that I have to force to clear? This is the trickiest part of this, because I can't reliably try an experiment and see if it worked. Adding the specific image UTI’s (public.jpeg, public.png) seemed to help, even though those types should conform to public.image, which conforms to public.data and public.content. Is it actually necessary to specify those? If the user selects multiple photos in the Photos app, my app doesn’t appear, but other third-party apps on my phone do. How can I support multiple photos? This configuration doesn't reliably show my app for Safari images - what do I need to do to make that happen? I had to use “public.data” when I briefly had Safari sharing working, but there doesn't seem to be a way to get a UTI from UIOpenURLContext. Right now, my code just tries to load the data as an image and aborts if UIImage(data:) returns nil. Is this a safe way of doing this? Is there a way to get the UTI for the data?
1
0
149
1w
Open an app from the photos share sheet
I'd like to add a share extension to my app (an Action app extension, I think). The extension would appear when users share a photo in the Photos app (and, ideally, Safari). If you tapped my app icon on the share sheet, iOS would pass the photo to my app and switch the user from Photos or Safari to my full app, with the shared photo(s) available for my app to work with. I know this is possible, because Instagram (a third-party app) works exactly like this. If you look at an image in the Photos app, tap Share and then tap Instagram, iOS will background the Photos app, activate the Instagram app and let you edit and post your photo in the main Instagram app. It seems like NSExtensionContext#open(_:completionHandler:) might do this if I add a custom URL to my main app, but the documentation for that says: Each extension point determines whether to support this method, or under which conditions to support this method. In iOS, the Today and iMessage app extension points support this method. That would rule out an Action, Photo Editing or Share extension. But then how does Instagram do this, and how can I achieve the same in my app? I know that it's possible for an Action, Photo Editing or Share extension to open as a mini-app on top of the app providing the content. But coordinating the IPC for that is much, much more work (for my particular app) than just switching the user over to the app, with full access to all the functionality and data that my main app usually has access to.
0
0
172
1w
Is it possible to use a list-style UICollectionView but have multiple columns?
I'm working on a UICollectionView that has a custom compositional layout with multiple columns. I wanted to add swipe actions to the cells (specifically, a delete action). I knew this was possible because of the existence of trailingSwipeActionsConfigurationProvider but I didn't realize that this is only for list layouts, created with UICollectionViewCompositionalLayout.list. But if I use a list layout, I don't think I have any opportunity to add multiple columns. Do I really have to choose between multiple columns and trailing swipe actions? Or is there some way to get both?
0
0
375
Jul ’24
Detecting Local Network issues with NWListener
I have an application that uses Bonjour to communicate with other instances of the app on other devices. If I start an NWBrowser and the user has "Local Network" turned off for my app, the stateUpdateHandler for the browser gets .waiting with an error containing the string "PolicyDenied." This lets me show an alert to the user explaining what's happening, with a link to the app's Settings screen. But if I use NWListener (the counterpart of NWBrowser) and have "Local Network" turned off, there's no indication of any problem. After I start the listener, stateUpdateHandler is called with .ready as the state - even though it's not really ready to listen at all. The FAQ for Local Network Privacy suggests that any Bonjour operation will raise kDNSServiceErr_PolicyDenied if Local Network is off. However, in my application, that only seems to be true for browsing, not listening. Is there a way to detect a missing Local Network entitlement for NWListener? I know there are solutions involving sending a message to localhost, etc, but ideally there would be something simpler.
1
0
605
Jun ’24
Sendability for Stream, InputStream, etc.
I have a project with some legacy networking code that uses the Stream (formerly NSStream) family of classes, including Stream, InputStream, OutputStream, and StreamDelegate. None of these are sendable, so I get a lot of warnings when implementing delegate methods in a @MainActor class. These classes seem like they could be sendable. Is this something that will happen soon? Is it a bug I should report? The networking code that uses these classes runs great, and hasn't needed changes for years, so my current solution is to just mark these unchecked: extension Stream: @unchecked Sendable { } extension InputStream: @unchecked Sendable { } extension OutputStream: @unchecked Sendable { } This makes the compiler happy, but makes me feel kind of bad. Is there something else I could do?
1
0
525
Jun ’24
How do I handle changes from sync with Swift Data?
In Core Data, you can use a pinned query generation to make sure that your app is working from a consistent view of the data store. If you have CloudKit sync turned on, and new changes come in that invalidate relationships, your app won't see them right away as long as it's looking at a pinned query generation. Since Swift Data doesn't yet support query generations, how do I deal with this issue in Swift Data apps? For example, let's say I have an address book app. I open a particular contact, and then tap a control on the screen that opens a list of images for that contact. While looking at the images, CloudKit sync retrieves changes made by other devices, which have completely removed the parent contact. How does my app know this has happened? Suppose the image browser screen needs to refer to the parent contact, or make changes to it, but the contact is no longer there because a background sync removed it.
1
0
704
Jun ’24
Show a UIMenu on double-tap?
Is there a way to programmatically show a UIMenu on iOS on a double-tap event? I have an app that's been around for over a decade, so there are some UX patterns that I'm reluctant to mess around with. There is a view in my app with the following properties: Tapping the view once focuses it and brings it to the front Double-tapping it shows a view controller as a sheet, with several operations you can perform on that object Instead of the sheet, I'd like to move to context menus - they look better, and they're more familiar for users. Obviously, adding a context menu for long-press is straightforward (just use UIContextMenuInteraction). But there does not seem to be a way to show the context menu on double-tap. I've discovered that you can use UIButton with showsMenuAsPrimaryAction to show the menu on single-tap, but that doesn't quite work for me. My users expect a single tap to do something else (focus the view) and will be annoyed if single taps start showing menus instead. So, is there a way to show a context menu on double tap in iOS?
1
0
645
Jun ’24
How do I resolve conflicts with SwiftData?
SwiftData includes support for CloudKit sync. However, I don't see any way to add conflict resolution behavior. For example, if different devices set different values for a field, or if a relationship is orphaned because of a deletion on another device, the application has to handle this somehow. In Core Data (which SwiftData wraps), you can handle this with the conflict resolution system (docs) and classes like NSMergePolicy. Is any of this accessible in SwiftData? If not, how do you deal with conflicts when syncing a SwiftData model with the cloud?
2
1
887
May ’24
Run UI tests on multiple devices in succession?
The new test report, with the automatic video recording and scrubber, is great. I'm setting up different configurations for different languages to improve localization testing, but I was wondering if it was possible to make the simulator device type part of the configuration. For example, I'd like to have a single test plan with an "iPhone 14" test plan, an "iPad Air" test plan, etc. Then I would just press Cmd-U, and Xcode would run through each device in sequence, leaving me with videos of each test run that I could review in the test report. Is that possible?
2
1
2.2k
Jun ’23
How do I use Xcode Previews in an app that has to support iOS 16?
Xcode Previews are a great new feature, and I've been adding #Preview blocks to some of my more complex UIKit files so I can tweak their UI without running the app. It's been a blast so far. The only problem is that I apparently have to set my project deployment target to iOS 17.0 to use them at all. If I set it to iOS 16.0, I get these errors: 'Preview' is only available in iOS 17.0 or newer 'init (_:traits:body:' is only available in iOS 17.0 or newer 'UVPreviewRegistry' is only available in iOS 17.0 or newer 'Preview' is only available in iOS 17.0 or newer 'init (_:traits:body:' is only available in iOS 17.0 or newer I tried surrounding #Preview with an @availability block for iOS 17, but got the same errors. My goal is to be able to leave useful #Preview blocks in my source code, but still set my deployment target to iOS 16. Is this possible?
1
1
3.5k
Jun ’23
How do I use async/await with NotificationCenter?
In the Meet AsyncSequence talk, there's a very cool use case that's shown in one of the slides - the new notifications property on NotificationCenter is an async sequence and the code sample does something like: let notification = await center.notifications(named: ....).first { ... } This seems really intriguing and useful to me but I had a few questions about the details of how this works: What is the type of notification in this snippet? A Task? Where would I store this value? What context should this be invoked in, especially if I want to have a long-running notification filter running that will remain active for the lifetime of the app? Basically, I'm curious to see an example of the code surrounding this snippet.
3
0
6.3k
Jun ’21
How can I tell if NetService#publish is failing because it lacks permissions?
I'm testing my app on iOS 14. One of its features involves listening for Bonjour connections on the local network using NetService#publish. When my app calls this method for the first time, I get the new iOS 14 popup asking the user if my app should have access to the local network. If they allow access, everything is fine. However, if the user denies access, my NetService delegate never receives netService(didNotPublish:). I was hoping to get an error code here that I could use to inform the user that the feature isn't working specifically because they disabled the Local Network permission. Unfortunately, this is not treated as an error condition - the only way I've found to detect this situation at all is that my netService(didPublish:) method never gets called if the Local Network permission has been disabled. Is there a better way to detect this situation and inform the user that the app needs Local Network access to continue?
6
0
2.0k
Aug ’20