Post

Replies

Boosts

Views

Activity

How can I use UICollectionViewDiffableDataSource reorderHandlers with a custom compositional layout?
As of iOS 14, UICollectionViewDiffableDataSource has a reorderHandlers property. It's demonstrated in some sample code and talked about in WWDC 2020 session on Advances in Diffable Data Sources. The presenter states that you have to provide a canReorder and didReorder closure to enable the feature. The sample code uses it in a collection view with a list layout configuration, and configures the list cells with reorder accessories. The canReorder and didReorder methods are called as expected. But if I remove the reorder accessories from the cells, reordering no longer works - it doesn't call either closure. It also doesn't work in my app, where I have a grid layout using a compositional layout. How do I enable reordering on UICollectionViewDiffableDataSource without list cells and reorder accessories?
2
0
533
Nov ’21
How do I implement drop operation in UICollectionView drag and drop with an async data source and cell registration?
I have a UICollectionView tied to a UICollectionViewDiffableDataSource, and I'm generating and applying snapshots to the datasource on a background serial queue, and generating cells using UICollectionViewCellRegistration. I'm working on supporting reordering of the contents of the collection view via drag and drop, and I'm having trouble with what to do in collectionView:performDropWithCoordinator: so the reorder animation looks right. Normally, I would do something like this: -(void)collectionView:(UICollectionView *)collectionView performDropWithCoordinator:(id<UICollectionViewDropCoordinator>)coordinator { NSIndexPath *sourcePath = (NSIndexPath *)coordinator.items.firstObject.dragItem.localObject; NSInteger fromIndex = sourcePath.item; NSInteger toIndex = coordinator.destinationIndexPath.item; NSNumber *fromItem = [self.datasource itemIdentifierForIndexPath:sourcePath]; NSNumber *toItem = [self.datasource itemIdentifierForIndexPath:coordinator.destinationIndexPath]; //Do the move in the data model [MyModel moveItemFrom:fromIndex to:toIndex]; //Do the move in the datasource. This is the data source equivalent of: //[collectionView moveItemAtIndexPath:sourcePath toIndexPath:coordinator.destinationIndexPath]; NSDiffableDataSourceSnapshot *snap = self.datasource.snapshot; if (toIndex < fromIndex) [snap moveItemWithIdentifier:fromItem beforeItemWithIdentifier:toItem]; else [snap moveItemWithIdentifier:fromItem afterItemWithIdentifier:toItem]; [self.dataSource applySnapshot:snap animated:YES]; //Drop the item [coordinator dropItem:coordinator.items.firstObject.dragItem toItemAtIndexPath:coordinator.destinationIndexPath]; } But because my datasource updates happen on a background queue, I have to do at least the snapshot generation and application asynchronously, and I'd like to do the actual data model modification there too to avoid hangs. And I need to call dropItem on the coordinator on the main queue in this method. This results in an odd animation where the dropped item momentarily disappears (when drop is called) and then reappears (when the data source is updated on the background queue). The best idea I have so far is to use UICollectionViewDropPlaceholder to hold the place in the collection view until the data source is updated. But to create a placeholder I need a cell reuse identifier (docs on init method), and I don't have one of those because I'm creating my cells using cell registrations. So my question: what do I do in the performDrop method to make this work correctly? If the placeholder is the right idea, how do I use it in this situation?
2
0
870
Nov ’21
Error about Siri capability exporting Catalyst app as Developer ID
I'm working on enabling Catalyst for my existing iOS app. When I try to archive and export Catalyst as a Developer ID-signed Mac app, I get the following error: Cannot create a Mac Catalyst Developer ID provisioning profile for "[my bundle ID]". The Siri capability is not available for Mac Catalyst Developer ID provisioning profiles. Disable this feature and try again. My iOS app uses SiriKit to donate a Siri intent, so Siri is among the capabilities listed in the Signing and Capabilities tab in the project inspector in Xcode. I don't see a way to turn that capability off only for Catalyst (like you can link some frameworks only for Catalyst or iOS), and I don't want to disable Siri entirely in my iOS app. What's going on here? What do I need to do to "disable this feature" for Catalyst?
2
0
1.1k
Jun ’21
How can I tell if a StoreKit 2 purchase was completed on _this_ device?
In the session on StoreKit 2 (which looks amazing!), the presenter says: In fact, if your app is running when a purchase is made on another device, you'll be notified about the new transaction. This seems to mean that when an app uses the listener API to be notified of transactions, it will get transactions that happened on other devices. My app offers purchases across other platforms in addition to iOS, and when a purchase happens we register it with our own account system. If a user has the app running on both their iPad and iPhone and makes a purchase on the phone, if the iPad gets notified of it the same way it would of a purchase made on the iPad, both devices will try to report it to our system. This seems undesirable. What's the recommended approach here? Should we just make sure our system will disregard duplicate transaction reports? Or is there a way to know whether a transaction originated on this device? I don't see a property on the transaction type that looks like it could accomplish this. Maybe the deviceVerification properties? But that's seems more like the new edition of transaction receipt verification - failing that check would presumably mean that the purchase is invalid, not that it didn't happen on this device...?
2
0
2.7k
Jun ’21
Pricing of Pay As You Go subscription introductory offer
I want to offer a pay-as-you-go introductory offer for a subscription in my iOS app. But it's not clear to me what the actual pricing is if the offer is on a subscription whose period is more than 1 unit (2 month, 3 month, 6 month, etc). For example, say I have a subscription that costs $20 per renewal and renews every 6 months. I set up an intro offer of the "Pay as you go" type (SKProductDiscountPaymentModePayAsYouGo) whose duration is 12 months and price is $10. Is the user going to get charged $10/month for 12 months (renewing 12 times), or $10 per 6 months for 12 months (renewing twice)? The documentation - https://developer.apple.com/documentation/storekit/in-app_purchase/subscriptions_and_offers/implementing_introductory_offers_in_your_app?language=objc isn't all that clear on this. If I set this up with a local StoreKit test file - https://developer.apple.com/documentation/xcode/setting_up_storekit_testing_in_xcode?language=objc and try it in a simulator, the system purchase sheet appears to actually display it wrong. In my scenario above, the simulator shows a trial of "$10 per month for 2 months". I've filed this as FB8998598.
1
0
1.1k
Feb ’21
How to use Link in WidgetKit to define arbitrary regions, not just text links?
In the session "Widgets Code Along Part 2" in WWDC 2020, the presenter says - https://developer.apple.com/videos/play/wwdc2020-10035/?time=174: Widgets do not have animation or custom interactions, but we can deep link from our widget into our app. SystemSmall widgets are one large tap area, while systemMedium and systemLarge can use the new SwiftUI link API to create tappable zones within the widget. This suggests that I should be able to designate regions of my widget as tappable that lead to a given URL in my app. But the Link - https://developer.apple.com/documentation/swiftui/link API just takes a string title and a destination URL - it doesn't appear to be able to embed other arbitrary views like images. How do I use the Link API to designate regions of my widget as tappable, instead of just text links?
1
0
1.9k
Sep ’20
How do I interpret hang / CPU usage diagnostic files for macOS? Documentation?
Cross-posted on Stack Overflow - https://stackoverflow.com/q/64105606/412107. If my Mac app hangs, it generates diagnostic files that end in .hang or .cpu_resource.diag. They look somewhat like crash reports, but with deep tab-indented hierarchies of what looks like process samples. Example: Powerstats for:&#9;MyApp [13095] thread 0x9b152 UUID:&#9;&#9;&#9;&#9;&#9;&#9;35BE255F-F3B3-3188-B1E4-12E96CAAD397 Start time:&#9;&#9;&#9;2020-09-26 15:37:35 -0500 End time:&#9;&#9;&#9;&#9;2020-09-26 15:39:03 -0500 Parent:&#9;&#9;&#9;&#9;&#9;launchd Microstackshots: 55 samples (47%) Primary state:&#9; 52 samples Frontmost App, User mode, Thread QoS User Interactive User Activity:&#9; 0 samples Idle, 55 samples Active Power Source:&#9;&#9;0 samples on Battery, 55 samples on AC &#9;55 start + 1 (libdyld.dylib) [0x7fff8bed55ad] &#9;&#9;55 main + 121 (MyApp) [0x108ee8d5f] &#9;&#9;&#9;55 NSApplicationMain + 1176 (AppKit) [0x7fff8ffed368] &#9;&#9;&#9;&#9;55 -[NSApplication run] + 682 (AppKit) [0x7fff90023d80] &#9;&#9;&#9;&#9;&#9;55 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454 (AppKit) [0x7fff9002f226] &#9;&#9;&#9;&#9;&#9;&#9;55 _DPSNextEvent + 1067 (AppKit) [0x7fff9002fdf6] &#9;&#9;&#9;&#9;&#9;&#9;&#9;55 _BlockUntilNextEventMatchingListInModeWithFilter + 71 (HIToolbox) [0x7fff866e35af] &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;55 ReceiveNextEventCommon + 184 (HIToolbox) [0x7fff866e3677] &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;55 RunCurrentEventLoopInMode + 235 (HIToolbox) [0x7fff866e3935] &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;55 CFRunLoopRunSpecific + 328 (CoreFoundation) [0x7fff973d5e48] &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;55 __CFRunLoopDoObservers + 391 (CoreFoundation) [0x7fff973f6f37] &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;55 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23 (CoreFoundation) [0x7fff973f6fc7] &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;55 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 71 (QuartzCore) [0x7fff99fcf863] ...and on and on, much deeper How do I interpret these diagnostic files? Can someone link to some Apple documentation of them?
1
0
1.5k
Sep ’20
Is the text color of UICollectionView index views modifiable?
I notice in iOS 14 beta 4, collection views show index views on their trailing edge if the data source implements indexTitlesForCollectionView - https://developer.apple.com/documentation/uikit/uicollectionviewdatasource/2851455-indextitlesforcollectionview?language=objc and indexPathForIndexTitle - https://developer.apple.com/documentation/uikit/uicollectionviewdatasource/2851456-collectionview?language=objc. But I don't see a way to control any aspect of its appearance. On UITableView this shows up as the sectionIndexColor - https://developer.apple.com/documentation/uikit/uitableview/1614915-sectionindexcolor?language=objc property. Does this property exist on UICollectionView somewhere I didn't think to look? Or is it just not there (yet)? FB8284500
3
0
1.2k
Aug ’20
What's the best way to create a fully dynamic UIMenu for a UIButton or UIBarButtonItem?
I've got a UIBarButtonItem in my app that currently presents an action sheet of items. I want to switch this to a UIMenu with iOS 14's new APIs for buttons and bar button items. But somme of the contents of the action sheet change based on the state of the view controller when the action sheet is triggered. With the action sheet, I generate a different action sheet every time the bar button item's target action is called. But with the new APIs, I have to generate the menu ahead of time and assign it to the button. What's the best way to get the menu to update every time it's presented? I tried UIDeferredMenuElement, but it caches the result of its provider. Feedback FB7824467 suggests adding a property to UIDeferredMenuElement to disable the caching of the provider result.
2
0
3.6k
Jul ’20
Doxygen Comments and Xcode Code Completion
I've got some C++ code with Doxygen documentation comments (the /**-style kind), and I'd love it if those showed up in Xcode's code completion. They do show up in Quick Help. And the triple-slash style documentation comments do show up in code completion. Anyone know how to make this work? Filed as Feedback FB7824467 with a sample project and screenshots.
0
0
521
Jun ’20