I'm seeing some hang reports for my app in the Xcode organizer that boil down to [AAAttribution attributionTokenWithError:]. The docs for that method talk a lot about a request to Apple's services, but it looks like that's about passing the fetched token up to be decoded...but is the method also making a network request? Or is it doing something else that shouldn't be done on the main thread? If it wasn't main-thread safe I'd expect it to be documented as such, or for the Swift version to be async...
Post
Replies
Boosts
Views
Activity
I am working on supporting some formatted text editing in my app, and I've been experimenting with copy and paste support for formatted text. I discovered that NSAttributedString implements NSItemProviderWriting, which means I can give it to UIPasteboard via setObjects and all the built-in attributes transfer perfectly if I then paste it into another text view, or even another app that behaves itself.
But if I have custom attributes in my attributed string, having their values implement Codable doesn't let them transfer across the clipboard. In my implementation of textPasteConfigurationSupporting(_: transform:), I try to get an attributed string like this:
let attr = item.itemProvider.loadObject(ofClass: NSAttributedString.self) { val, err in
//...handle here
}
I get an error like this:
Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type com.apple.uikit.attributedstring" UserInfo={NSLocalizedDescription=Cannot load representation of type com.apple.uikit.attributedstring, NSUnderlyingError=0x600003e7bea0 {Error Domain=NSCocoaErrorDomain Code=260 "The file “b036c42113e34c2f9d9af14d6fefcbd534f627d6” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///Users/username/Library/Developer/CoreSimulator/Devices/86E8BDD4-B6AA-4170-B0EB-57C74EC7DDF0/data/Library/Caches/com.apple.Pasteboard/eb77e5f8f043896faf63b5041f0fbd121db984dd/b036c42113e34c2f9d9af14d6fefcbd534f627d6, NSFilePath=/Users/username/Library/Developer/CoreSimulator/Devices/86E8BDD4-B6AA-4170-B0EB-57C74EC7DDF0/data/Library/Caches/com.apple.Pasteboard/eb77e5f8f043896faf63b5041f0fbd121db984dd/b036c42113e34c2f9d9af14d6fefcbd534f627d6, NSUnderlyingError=0x600003e7ac70 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}}}
But I tried making my custom attribute values implement NSSecureCoding, and then it worked.
Why is Codable conformance not enough here? Is it because the code that serializes and deserializes is still in Objective-C and isn't aware of Codable? Will this change as the open-source Foundation in Swift work continues?
WWDC 2021 session 10064 introduced UIButtonConfiguration, a new way to configure the visual appearance of buttons, for iOS 15. I've run into a surprising bit of behavior with its image setup: if you give it an image from an asset catalog that's bigger than the button's bounds, the image is sized too big for the button.
See the attached screenshot of an example app. The upper play icon is a button set up with setImage:forState:, and it sizes the image down as expected. The lower one is set up with UIButtonConfiguration, and is constrained to the same size (both buttons have a red border), but its image is too big.
How do I control the image sizing behavior here?
FB12358840 if any engineers look at this and think there could be an API improvement here.
WWDC 2021 session 10064 introduced UIButtonConfiguration, a new way to configure the visual appearance of buttons, for iOS 15. I'm now in the process of switching all my button setup over to UIButtonConfiguration, and I've run into one situation where it doesn't apply: rounding specific corners of the button. CALayer has the maskedCorners property that lets you round or mask specific corners but not others. In transferring border radius, border width, and border color styling over to UIButtonConfiguration via UIBackgroundConfiguration, I don't see an equivalent UI. Am I missing something?
For now, in cases when I need the maskedCorners functionality, I'm falling back to using the layer for border properties.
I have an app that uses UITextView for some text editing. I have some custom operations I can do on the text that I want to be able to undo, and I'm representing those operations in a way that plugs into NSUndoManager nicely. For example, if I have a button that appends an emoji to the text, it looks something like this:
func addEmoji() {
let inserting = NSAttributedString(string: "😀")
self.textStorage.append(inserting)
let len = inserting.length
let range = NSRange(location: self.textStorage.length - len, length: len)
self.undoManager?.registerUndo(withTarget: self, handler: { view in
view.textStorage.deleteCharacters(in: range)
}
}
My goal is something like this:
Type some text
Press the emoji button to add the emoji
Trigger undo (via gesture or keyboard shortcut) and the emoji is removed
Trigger undo again and the typing from step 1 is reversed
If I just type and then trigger undo, the typing is reversed as you'd expect. And if I just add the emoji and trigger undo, the emoji is removed. But if I do the sequence above, step 3 works but step 4 doesn't. The emoji is removed but the typing isn't reversed.
Notably, if step 3 only changes attributes of the text, like applying a strikethrough to a selection, then the full undo chain works. I can type, apply strikethrough, undo strikethrough, and undo typing.
It's almost as if changing the text invalidates the undo manager's previous operations?
How do I insert my own changes into UITextView's NSUndoManager without invalidating its chain of other operations?
One of the things discussed in Understanding the exception types in a crash report is the 0xdead10cc code under EXC_CRASH (SIGKILL):
0xdead10cc (pronounced “dead lock”). The operating system terminated the app because it held on to a file lock or SQLite database lock during suspension.
My app gets killed this way here and there, and it's been on my project list for some time to make the requisite changes to database connection handling to fix it. With an App Store build, as far as I know it just means the app cold-starts when launched instead of resuming, but in a TestFlight build it actually shows a crash reporter dialog.
Reports of this issue from TestFlight users got more frequent with a recent update that had the effect of keeping more SQLite handles open longer, and I realized that I personally have never seen a crash reporter dialog after fast-app-switching away from a TestFlight build on my device. And I use the TF build as my daily driver, and I use my app a lot.
My question is this: is it possible that the 0xdead10cc crash doesn't happen on Developer Mode devices?
I'm adding some text formatting support to an editable text view in my app, and I want to include bulleted lists. I specifically want to have the standard behavior where if you're typing a line of text in a list and press Enter, the next bullet item is automatically inserted.
This appears to somewhat work out-of-the-box with NSTextList on iOS 16, unless the line you're editing is at the very end of the document. This is apparent in the sample code for WWDC 2022 session 10090 (project is here):
Run that sample app and switch to the List tab
Put your cursor at the end of any line except the last one and press enter. You get a new list item, as expected.
Put your cursor at the end of the very last line and press Enter. You don't get a list item until you type something on that line.
I've likewise found that if I have this text in a text view:
Hello World\n\nList here\n
If I format the text List here as a bulleted list (by creating an NSMutableParagraphStyle with its textLists property set and adding it to the attributed string for that range) and press Enter at the end of the word Here, I get a new bullet item automatically. But if I do the same thing without having that last newline after Here, the new list item is not inserted.
How can I make the list auto-continuation behavior work at the end of the document?
UILargeContentViewerInteraction, added in iOS 13, works out of the box on the tab bar in a UITabBarController, and it's easy to set up on a custom view using the UILargeContentViewerItem properties on UIView. But how do I set it up on a UITabBar that's not connected to a UITabBarController? There don't appear to be any relevant properties on UITabBarItem.
To try this, I made a sample app, added a tab bar, set up some items, set their largeContentSizeImage properties for good measure, ran the app, set text size to a large accessibility value, and long-pressed on the items, and I get no large content viewer.
I also tried adding a UILargeContentViewerInteraction to the tab bar, and implemented the viewControllerForInteraction method in the delegate.
I have an iOS app that I'm looking to make available as a Catalyst app. I have various view controllers that I present using custom animations and presentation styles via UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning, UIPresentationController, et al.
Most of the view controllers I present with my custom styles are UINavigationController instances (or subclasses thereof). And when I build and run my Catalyst app on Ventura, the titles and bar items for the navigation items of the view controllers in the navigation stack get moved to the title bar of the application, and the navigation bar doesn't appear at all in the presented view controller.
Why is this happening, and how do I stop it? I've looked through the documentation for the APIs I mentioned above and tried setting various things that seemed like they could conceivably be relevant - UIPresentationController.shouldPresentInFullscreen, UIViewController.modalInPresentation, etc - and have had no luck.
I work on an iOS app that displays images that often contain text, and I'm adding support for ImageAnalysisInteraction as described in this WWDC 2022 session. I have gotten as far as making the interaction show up and being able to select text and get the system selection menu, and even add my own action to the menu via the buildMenuWithBuilder API. But what I really want to do with my custom action is get the selected text and do a custom lookup-like thing to check the text against other content in my app.
So how do I get the selected text from an ImageAnalysisInteraction on a UIImageView? The docs show methods to check if there is selected text, but I want to know what the text is.
I have an iOS app that can play audio books as FairPlay DRM'd audio streams. I'm using AVContentKeySession to fetch keys and AVQueuePlayer to play. It works great on iOS, but on Catalyst (Monterey 12.3.1, M1 Max MacBook Pro) it crashes. When it happens in debug, I get a message "Too few bits left in input buffer" printed to the console, and an exception is thrown in the guts of what appears to be core media. Here's the output from [NSThread callStackSymbols] when paused on an exception breakpoint at that point:
0 ??? 0x0000000156b8cc9c 0x0 + 5749918876,
1 BRFree 0x000000010445cf08 main + 0,
2 AudioCodecs 0x0000000157918c24 _ZL11GetPropertyPvjPjS_ + 52,
3 AudioToolboxCore 0x00000001862536a4 _ZN15ADTSAudioStream11ParseHeaderER27AudioFileStreamContinuation + 1060,
4 AudioToolboxCore 0x000000018624259c AudioFileStreamParseBytes + 412,
5 MediaToolbox 0x00000001915f7d98 FigManifoldCreateForICY + 2176,
6 MediaToolbox 0x00000001915f7718 FigManifoldCreateForICY + 512,
7 MediaToolbox 0x00000001916bbd78 FigPlayerStreamCreate + 315920,
8 MediaToolbox 0x0000000191a269a0 FigMetadataConverterCreateForQuickTimeToFromiTunes + 45888,
9 MediaToolbox 0x0000000191a4a290 FigMetadataConverterCreateForQuickTimeToFromiTunes + 191536,
10 MediaToolbox 0x0000000191a2a470 FigMetadataConverterCreateForQuickTimeToFromiTunes + 60944,
11 MediaToolbox 0x0000000191a28c34 FigMetadataConverterCreateForQuickTimeToFromiTunes + 54740,
12 MediaToolbox 0x0000000191a413b4 FigMetadataConverterCreateForQuickTimeToFromiTunes + 154964,
13 MediaToolbox 0x0000000191a2f144 FigMetadataConverterCreateForQuickTimeToFromiTunes + 80612,
14 MediaToolbox 0x00000001917cae64 FigAlternateFilterMonitorCreateForThermalNotification + 30428,
15 MediaToolbox 0x00000001917ccb44 FigAlternateFilterMonitorCreateForThermalNotification + 37820,
16 MediaToolbox 0x00000001917cb134 FigAlternateFilterMonitorCreateForThermalNotification + 31148,
17 CFNetwork 0x0000000189937cd4 _CFHostIsDomainTopLevelForCertificatePolicy + 27728,
18 Foundation 0x0000000185ba980c __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 24,
19 Foundation 0x0000000185ba96b4 -[NSBlockOperation main] + 104,
20 Foundation 0x0000000185ba9644 __NSOPERATION_IS_INVOKING_MAIN__ + 24,
21 Foundation 0x0000000185ba88dc -[NSOperation start] + 788,
22 Foundation 0x0000000185ba85c0 __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 24,
23 Foundation 0x0000000185ba8478 __NSOQSchedule_f + 184,
24 libdispatch.dylib 0x00000001099f60f4 _dispatch_block_async_invoke2 + 148,
25 libdispatch.dylib 0x00000001099e2394 _dispatch_client_callout + 20,
26 libdispatch.dylib 0x00000001099eb778 _dispatch_lane_serial_drain + 980,
27 libdispatch.dylib 0x00000001099ec814 _dispatch_lane_invoke + 492,
28 libdispatch.dylib 0x00000001099f9fc8 _dispatch_root_queue_drain + 408,
29 libdispatch.dylib 0x00000001099f9d3c _dispatch_worker_thread + 264,
30 libsystem_pthread.dylib 0x00000001094e1890 _pthread_start + 148,
31 libsystem_pthread.dylib 0x00000001094ebaa8 thread_start + 8
In the Debug Navigator, the top of the stack looks a little different:
#0 0x0000000184bdeb3c in __cxa_throw ()
#1 0x000000015791941c in ACMP4AACLowComplexityDecoder::GetProperty(unsigned int, unsigned int&, void*) ()
#2 0x0000000157918c24 in GetProperty(void*, unsigned int, unsigned int*, void*) ()
#3 0x00000001862536a4 in ADTSAudioStream::ParseHeader(AudioFileStreamContinuation&) ()
#4 0x000000018624259c in AudioFileStreamParseBytes ()
#5 0x00000001915f7d98 in ___lldb_unnamed_symbol598$$MediaToolbox ()
What's going wrong here? Can anyone give me direction on what to fix? Or is FairPlay audio not even expected to work in Catalyst at this point?
I have an iPad app in which I'm starting to support multiple windows / scenes. I have one main window type, let's say MainScene, and at least one secondary window type for opening specific types of content, say DetailScene.
I have not declared my scene types in Info.plist. I have implemented application:configurationForConnectingSceneSession:options: like this:
-(UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options
{
NSUserActivity *activity = options.userActivities.anyObject;
NSString *activityType = activity.activityType;
if ([activityType isEqualToString:@"detailType"])
return [DetailSceneDelegate makeSceneConfiguration];
return [MainSceneDelegate makeSceneConfiguration];
}
Say I perform these steps:
Launch app for the first time. I get a call to configurationForConnectingSceneSession, and the activity type is nil so it returns a MainScene.
Open a new window for some piece of content. That uses the detail scene activity type, so configurationForConnectingSceneSession returns a DetailScene. Creating the new scene looks like this:
NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:@"detailType"];
activity.userInfo = @{@"content_id": @(contentRowId)};
[[UIApplication sharedApplication] requestSceneSessionActivation:nil userActivity:activity options:nil errorHandler:nil];
Suspend the app and open the app switcher. Discard (by flicking up) first the main window and then the detail window. The app is now killed.
Relaunch the app.
At this point I do not get a call to configurationForConnectingSceneSession. I get the detail scene back, restored from its user activity, with calls straight to DetailSceneDelegate.
My question: how do I control what scene gets restored in this situation? I want my main scene to come back.
Messages and Mail and Notes all do this. If you open Messages and drag a conversation out into a new window, you get a window for that conversation with a Done button in the corner that will dismiss the window. If you perform my steps above with Messages, you will relaunch to the full Messages view. Are they converting the detail view to a main view on the fly? Or is there a way to tell the system that the detail scene is secondary and should not be restored first, or that I should get asked what I want to restore via configurationForConnectingSceneSession? Or something else?
I have a UICollectionView that I feed data into using UICollectionViewDiffableDataSource. I want to display a scroll scrubber on the trailing edge of it, like I'd get if I implemented the data source methods indexTitlesForCollectionView and indexPathForIndexTitle. But the data source is the diffable data source object, and there's no property or closure on it to supply index titles as of iOS 15.
How are index titles supposed to work with UICollectionViewDiffableDataSource?
I work on an e-reader app that sells books as IAPs. We have a lot - about 20,000 or so. This is over Apple's limit of 10,000 IAPs, so we've had to ask them to raise the limit for us more than once. Recently, at Apple's suggestion, we finally switched to a mechanism called Price Tiers, where instead of having one IAP item in App Store Connect for each of our products, we have one item per price level, so if the user buys product ID (in our system) 12345 for $5, instead of buying non-consumable IAP ID com.mycompany.myapp.12345, they buy consumable IAP ID com.mycompany.myapp.price_tier.5. In our system, we link the purchase to product 12345 at the time of receipt verification and everything works great.
But I have an issue that manifests when the user is using Ask to Buy or when receipt validation fails in our back-end, I don't call finishTransaction, and the transaction is retried later. The sequence is this:
User buys product 12345, which is com.mycompany.myapp.price_tier.5
The user has Ask to Buy enabled, so the transaction ends in the deferred state, and the IAP flow on the device is done for now
At some point later, the user gets permission for the purchase, and my SKPaymentQueue delegate gets notified of the transaction again in the background
But at the point of step 3, I have no way of knowing what product in our system the transaction is for. The same issue occurs if receipt verification fails on our end - I don't call finishTransaction, so StoreKit retries it later, but again at that point I don't know which one of our products to register to the user's account.
How do I make Ask to Buy (or any situation where I get notified of a transaction outside of a user-driven purchase) work with Price Tiers?