Construct and manage graphical, event-driven user interfaces for iOS or tvOS apps using UIKit.

UIKit Documentation

Post

Replies

Boosts

Views

Activity

MPMediaQuery is always nil for Movie or TV Shows
Hello,I can no longer query for user's Movie or TV Shows. This used to work before iOS 9. MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue:[NSNumber numberWithInteger:MPMediaTypeMovie] forProperty:MPMediaItemPropertyMediaType]; MPMediaQuery *query = [[MPMediaQuery alloc] init]; [query addFilterPredicate:predicate]; NSArray *items = [query items];Returns nothing. As does MPMediaTypeTVShow.Any hints ? Thanks.
2
1
662
Jan ’16
Clearing cookies in SFSafariViewController?
I am using SFSafariViewController to authenticate against a website (SAML idP) and retaining my session using a cookie. I opted to use SFSafariViewController because my users could log in to the site using Safari or another app's instance of SFVC to achieve single sign on because as I understand it, the cookie store between native Safari and instances of SFSafariViewController are more or less shared. However, clearing the cookies in Safari settings in the settings app doesn't clear the cookies in my app's instance of SFVC. I have also tried logging out of the site in Safari but the cookie / session is still retained in my app's instance of SFVC.Is this expected behavior from SFVC?Thanks,Lucas
5
1
9.4k
Jan ’16
Launching iOS app from iCloud Drive
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).
11
1
40k
May ’16
NSURLSession data tasks always buffer the first 512 bytes unless content type is JSON?
Does NSURLSession data tasks buffer the first 512 bytes before it calls URLSession:dataTask:didReceiveResponse:completionHandler: as well as URLSession:dataTask:didReceiveData:? And is the buffering disabled when the Content-Type is application/json?I was experimenting with NSURLSession and was hoping to make it possible for my app to do something as soon as the HTTP header is received or as the first batch of raw data is received. I wrote a simple server to test, but what I described below can also be tested with services like httpbin.org. I noticed that:URLSession:dataTask:didReceiveResponse:completionHandler: is only called before URLSession:dataTask:didReceiveData: is called, though the doc says the former "[tells] the delegate that the data task received the initial reply (headers) from the server", and I thought it meant that the delegate method would be called as soon as the header is received even if the response body is not yet seen, but that doesn't seem to be the case.URLSession:dataTask:didReceiveData: is only called for the first time when the server sends 512 bytes in total (or closes the connection if the total content length is less than that). After the first 512 bytes, the delegate method is called as soon as a new batch of data is received. If Transfer-Encoding is used for chunking, the 512 bytes apply to the decoded bytes, not the raw bytes over the wire.However, if Content-Type is application/json, URLSession:dataTask:didReceiveData: will be called as soon as one byte is received. This Stack Overflow discussion mentioned this seemingly undocumented behavior.One can see the buffering in action with a simple HTTP server, or just use httpbin.org, for example with https://httpbin.org/drip?numbytes=1024&duration=8; if you use "curl -N" to fetch that URL, you'll see some characters received soon after the the request started, but if you use a data task to fetch it, it'll be a few seconds until the two delegate methods mentioned above are called, and the first batch of data is always >= 512 bytes long.The thing about this is that they don't seem to be documented anywhere, and I appreciate if there are some clarifications on the API contract. Thanks!
6
1
2.5k
Oct ’16
Traffic Attribution for Universal Links
I would really like to turn on Universal Links for our app, but our SEO team keeps preventing us from doing it. They say, they need to know where traffic is coming from. For example, when a user opens Google in Safari and finds our URL, and taps it, they want to know he came from Google. (Btw. Our app is a wrapper for a website, however with features not available to mobile web users - not sure if that is relevant.)Is there any way in iOS to get a URL, or any other traffic source information at all, that would allow us to track where app users are coming from?
5
0
5.2k
Oct ’16
StoryBoard Launch Screen not appearing
Hi guys,in the past I had the issue that images in the StoryBoard-created launch screen (splash screen) did not appear. Now it's getting worse:No matter what I put in the LaunchScreen.storyboard (images, labels) the splash screen of my app remains black on my iPhoneOn the simulator the splash screen appears fine!I created a new app, only generating a splash screen, and it worked fine on my iPhone and on the SimulatorI copied the LaunchScreen.storyboard of this new app and put it in the problematic app and the problem persists.I rebooted the iPhone, rebooted the Mac, nothing helps. The launchscreen is 100% black on startup. This is driving me crazy. Any suggestions?
4
1
11k
Oct ’19
Can I launch another CarPlay app from a CarPlay app?
I want to switch from a running CarPlay appto another CarPlay app without going through CarPlay HOME.I have tried openURL using URL scheme.As a result, the app started on the smartphone,but the app on the Simulator did not switch.I would like to know the URLif there is official information on CarPlay application switching.
2
0
1.6k
Feb ’20
Crash apparently caused by auto-layout UI changes on background thread
I've been getting occasional crash reports that look similar to this:Fatal Exception: NSInternalInconsistencyException Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread. Fatal Exception: NSInternalInconsistencyException 0 CoreFoundation 0x19dcd0a48 __exceptionPreprocess 1 libobjc.A.dylib 0x19d9f7fa4 objc_exception_throw 2 Foundation 0x19e1a6f08 -[NSISEngine tryToOptimizeReturningMutuallyExclusiveConstraints] 3 Foundation 0x19dfa803c -[NSISEngine withBehaviors:performModifications:] 4 UIKitCore 0x1a20ff8e8 -[UIView(UIConstraintBasedLayout) _resetLayoutEngineHostConstraints] 5 UIKitCore 0x1a21d9314 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] 6 QuartzCore 0x1a473c7dc -[CALayer layoutSublayers] 7 QuartzCore 0x1a4742958 CA::Layer::layout_if_needed(CA::Transaction*) 8 QuartzCore 0x1a474d578 CA::Layer::layout_and_display_if_needed(CA::Transaction*) 9 QuartzCore 0x1a4695f1c CA::Context::commit_transaction(CA::Transaction*, double) 10 QuartzCore 0x1a46bfc08 CA::Transaction::commit() 11 QuartzCore 0x1a46c0b8c CA::Transaction::release_thread(void*) 12 libsystem_pthread.dylib 0x19d9eefb0 _pthread_tsd_cleanup 13 libsystem_pthread.dylib 0x19d9ebde8 _pthread_exit 14 libsystem_pthread.dylib 0x19d9ece7c _pthread_wqthread_legacy_worker_wrap 15 libsystem_pthread.dylib 0x19d9ecc18 _pthread_wqthread 16 libsystem_pthread.dylib 0x19d9ef760 start_wqthreadThis is not being invoked by my code (at least directly). I've been running the app in the debugger with the Main Thread Checker enabled and have yet to catch whatever is causing this.I've found multiple reports from others who have been experiencing similar issues, most commonly on iOS 13. (My app only supports 13 and later.) I have yet to see any solid explanation. @Eskimo - is it possible that iOS is invoking something that results in a UI state change which is called from a background thread?Thanks,-S
16
1
7.8k
Feb ’20
An infinite CANVAS
I needed an infinite canvas for my app which is basically a drawing board where one can draw things using pen. So, I thought of having a very large custom UIView inside a UIScrollView. And in the custom view, I could keep drawing things. But, I ended up with a warning saying something like below and nothing drawn on screen. [<CALayer: 0x5584190> display]: Ignoring bogus layer size (50000, 50000) Which means, I can't have such a big CALayer to draw things. Now, solution? alternative? Then comes CATiledLayer. I made my large UIView backed by CATiledLayer now. After having a proper levelOfDetails and levelOfDetailsBias value, things worked like charm. Until I ended up facing another problem. Since, CATiledLayer caches drawing in different zoom levels if I try to scale the view after changing the drawing content the cached drawings appear and then the new contents get drawn. I don't find an option to invalidate caches in different levels. All the solutions I came across leads me to clear the entire contents of the CATiledLayer on drawing content change which won't help again. Do I miss something here? Is there a way with which I can clear caches at different levels? Or is there any other solutions which could solve my need? Can someone help me with this?
1
0
1.5k
Jul ’20
UITabBarController is unsupported as viewController
Hi, I'm testing one of my app on iOS 14 with Xcode 12 beta 3 (12A8169g) and I have a problem with my storyboards. Xcode give me this error for all the storyboards that contain a split view controller: An internal error occurred. Editing functionality may be limited. The log generated by the Xcode "Report a bug" button say: Exception name: NSInvalidArgumentException Exception reason: UITabBarController is unsupported as viewController for -[UISplitViewController setViewController:forColumn:] in Primary column It worked correctly on Xcode 12 beta 2. Has anyone encountered the same problem and found a way to fix it? Thank you
7
0
2.4k
Aug ’20
Voice Over accessibility: UITableView
In our app, we display contacts in UITableView. Let us say I have 300 contacts in my AddressBook, and all of them will be displayed in this table. Below this table, I have a UIButton to perform some action like invite selected contacts. With Voice Over enabled, when I get to the UITableView, it doesn't let me to proceed to the UIButton, unless I go over all 300 contacts. Is there a solution to override this and make it more friendly to the visually impaired users?
2
0
3.1k
Nov ’20
UITableViewAlertForCellForRowAtIndexPathAccessDuringUpdate when selected cells are reused.
I'm getting this message in console: [Assert] Attempted to call -cellForRowAtIndexPath: on the table view while it was in the process of updating its visible cells, which is not allowed. Make a symbolic breakpoint at UITableViewAlertForCellForRowAtIndexPathAccessDuringUpdate to catch this in the debugger and see what caused this to occur. Perhaps you are trying to ask the table view for a cell from inside a table view callback about a specific row? Table view: <UITableView: 0x10c04a000; frame = (0 0; 414 659); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x280262bb0>; layer = <CALayer: 0x280d302c0>; contentOffset: {0, 183.5}; contentSize: {414, 3068}; adjustedContentInset: {0, 0, 0, 0}; dataSource: <MyApp.MyDataSource: 0x282930ea0>> It happens when my table view is in editing mode, some cells are selected and are about to be reused (I'm scrolling the table and selected cells leave the visible area). I don't call -cellForRowAtIndexPath: or visibleCells directly in my code. Here's the stack trace when this happens: Thread 1 Queue : com.apple.main-thread (serial) #0 0x0000000185303650 in UITableViewAlertForCellForRowAtIndexPathAccessDuringUpdate () #1 0x0000000185303378 in -[UITableView _cellForRowAtIndexPath:usingPresentationValues:] () #2 0x00000001852f1bb0 in -[UITableView _updateSelectionGroupingForCell:atIndexPath:] () #3 0x00000001852f1e78 in -[UITableView _updateSelectionGroupingForVisibleCells] () #4 0x00000001852af9d0 in -[UITableViewCell showSelectedBackgroundView:animated:] () #5 0x00000001852b045c in -[UITableViewCell setSelected:animated:] () #6 0x00000001852adf5c in -[UITableViewCell prepareForReuse] () #7 0x000000018530b2b4 in -[UITableView _dequeueReusableViewOfType:withIdentifier:] () #8 0x000000018530b908 in -[UITableView _dequeueReusableCellWithIdentifier:forIndexPath:usingPresentationValues:] () #9 0x000000018530b764 in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] () #10 0x000000010103a4cc in MyDataSource.tableView(_:cellForRowAt:) at /../MyDataSource.swift:87 #11 0x000000010103a9f4 in @objc MyDataSource.tableView(_:cellForRowAt:) () #12 0x00000001853241ec in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] () #13 0x00000001852eff84 in -[UITableView _updateVisibleCellsNow:] () #14 0x000000018530e394 in -[UITableView layoutSubviews] () #15 0x0000000185643d90 in -[UIView(CALayerDelegate) layoutSublayersOfLayer:] () #16 0x0000000185b59384 in -[CALayer layoutSublayers] () #17 0x0000000185b59858 in CA::Layer::layout_if_needed(CA::Transaction*) () #18 0x0000000185b6dff8 in CA::Layer::layout_and_display_if_needed(CA::Transaction*) () #19 0x0000000185ab3ee0 in CA::Context::commit_transaction(CA::Transaction*, double, double*) () #20 0x0000000185adf36c in CA::Transaction::commit() () #21 0x0000000185ae06fc in CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) () #22 0x00000001826c3358 in CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION () #23 0x00000001826bd5c4 in __CFRunLoopDoObservers () #24 0x00000001826bdb74 in __CFRunLoopRun () #25 0x00000001826bd21c in CFRunLoopRunSpecific () #26 0x000000019973c784 in GSEventRunModal () #27 0x00000001850f6200 in -[UIApplication _run] () #28 0x00000001850fba74 in UIApplicationMain () #29 0x000000010111a824 in main at /.../MyApp/AppDelegate.swift:17 #30 0x000000018237d6c0 in start () This only happens in iOS 14.2, no such problem on iOS 13.7. Does it look like an UIKit bug? Does anyone know how to solve it?
4
0
2.6k
Dec ’20
Primary Language of Keyboard-Extension
I am writing a keyboard-extension, there are several buttons and these buttons have a text, therefor I am using localized strings. So the extension is always in the "correct" language. When opening the keyboard-extension with the "world"-button (pressing it long, so that the menu is shown) there is always a line below the name of the app showing "English". As far as I know this is the primary language, there is also one entry for "PrimaryLanguage" in the info.plist (NSExtension/NSExtensionAttributes, set to "en-US"). I tried to remove this entry, but after this the app does not start anymore. Is there a different way to remove this entry or is it possible to change it to the language of the localization?
2
0
2.4k
Jan ’21
State loops in UIViewRepresentable
I have been working with UIViewRepresentable a lot recently and noticed something that seems to be quite the flaw: There doesn't seem to be a clean way of passing data back to your swiftUI views in a performant way. Here is an example: struct MapWrapper: UIViewRepresentable { &#9;&#9;@Binding var centerCoordinate: CLLocationCoordinate2D &#9;&#9;init(centerCoordinate: Binding<CLLocationCoordinate2D>) { &#9;&#9;&#9;&#9;self._centerCoordinate = centerCoordinate &#9;&#9;} &#9;&#9;func makeUIView(context: Context) -> MKMapView { &#9;&#9;&#9;&#9;var mapView = MKMapView() &#9;&#9;&#9;&#9;mapView.delegate = context.coordinator &#9;&#9;&#9;&#9;return mapView &#9;&#9;} &#9;&#9; &#9;&#9;func updateUIView(uiView: MKMapView, context: Context) { &#9;&#9;&#9;&#9;// Updating the maps center coordinate triggers mapViewDidChangeVisibleRegion, which thus causes updateUIView to trigger again. &#9;&#9;&#9;&#9;uiView.centerCoordinate = centerCoordinate &#9;&#9;} &#9;&#9;func makeCoordinator() -> Coordinator { &#9;&#9;&#9;&#9;return Coordinator(parent: self) &#9;&#9;} &#9;&#9;class Coordinator: MKMapViewDelegate { &#9;&#9;&#9;&#9;var parent: MapWrapper &#9;&#9;&#9;&#9;init(parent: MapWrapper) { &#9;&#9;&#9;&#9;&#9;&#9;self.parent = parent &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;func mapViewDidChangeVisibleRegion(_ mapView: MKMapView) { &#9;&#9;&#9;&#9;&#9;&#9;// updating this variable causes a view reload, thus calling updateUIView, and eventually causing this delegate method to trigger again. &#9;&#9;&#9;&#9;&#9;&#9;parent.centerCoordinate = mapView.centerCoordinate } } As you can see from the above code, dragging the map anywhere would cause a loop. The only workaround I have found for this is to give your coordinator a "shouldUpdateState" Boolean variable. and set that prior to updating your bindings. Has this ever been addressed by apple anywhere? Or are we just expected to only modify our view state from the outside of a UIViewRepresentable?
3
1
2.9k
Jan ’21
App crashing randomly - Not possible to remove variable
** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Not possible to remove variable: 400: unknown var (bug!) with engine as delegate:0x283c8ed40{id: 33112} colIndex:32 from engine NSISEngine: 0x129248130{ delegate:0x12934eaa0 EngineVars:  0: objective{id: 33102} rowIndex:0  1: UIImageView:0x12924ec90.Height{id: 32592} rowIndex:1073741824  2: 0x280a04be0.marker{id: 32591} colIndex:1073741825  3: UIImageView:0x12924ec90.Width{id: 32807} rowIndex:1  4: 0x280dc35a0.posErrorMarker{id: 32871} colIndex:1  5: 0x280dc35a0.negError{id: 32872} rowIndex:88  6: 0x280dc3d80.posErrorMarker{id: 32873} colIndex:1073741826  7: 0x280dc3d80.negError{id: 32874} rowIndex:1073741825  8: UIImageView:0x129353f00.Width{id: 32594} rowIndex:2  9: 0x280979d60.marker{id: 32593} colIndex:3 10: 0x280dc1e60.posErrorMarker{id: 32875} colIndex:4 11: 0x280dc1e60.negError{id: 32876} rowIndex:3 12: UIImageView:0x129353f00.Height{id: 32822} rowIndex:1073741826 13: 0x280dc39c0.posErrorMarker{id: 32877} colIndex:1073741827 14: 0x280dc39c0.negError{id: 32878} rowIndex:1073741898 15: UIButton:0x1293540d0.Width{id: 32817} rowIndex:4 16: 0x280dc2040.posErrorMarker{id: 32879} rowIndex:93 17: 0x280dc2040.negError{id: 32880} colIndex:6 18: UIButton:0x1293540d0.Height{id: 32820} rowIndex:1073741827 19: 0x280dc3de0.posErrorMarker{id: 32881} rowIndex:96 20: 0x280dc3de0.negError{id: 32882} colIndex:1073741830 21: UILabel:0x129353300.Width{id: 32811} rowIndex:5 22: 0x280dc3e40.posErrorMarker{id: 32883} colIndex:44 23: 0x280dc3e40.negError{id: 32884} rowIndex:90 24: UILabel:0x129353300.Height{id: 32842} colIndex:1073741828 25: 0x280dc27c0.posErrorMarker{id: 32885} colIndex:1073741831 26: 0x280dc27c0.negError{id: 32886} rowIndex:1073741828 27: UILabel:0x129353c90.Width{id: 32840} rowIndex:6 28: 0x280dc1da0.posErrorMarker{id: 32887} colIndex:9 29: 0x280dc1da0.negError{id: 32888} rowIndex:97 30: UILabel:0x129353c90.Height{id: 32829} colIndex:1073741832 31: 0x280dc31e0.posErrorMarker{id: 32889} colIndex:1073741833 32: 0x280dc31e0.negError{id: 32890} rowIndex:1073741900 33: UIImageView:0x12934e490.Width{id: 32596} rowIndex:1073741905 34: UIImageView:0x12934e490.Height{id: 32597} colIndex:1073741844 35: 0x280963a70.marker{id: 32595} colIndex:11 36: 0x280dc2ee0.posErrorMarker{id: 32891} colIndex:12 37: 0x280dc2ee0.negError{id: 32892} rowIndex:8 38: 0x280dc1d40.posErrorMarker{id: 32893} colIndex:1073741835 39: 0x280dc1d40.negError{id: 32894} rowIndex:1073741830 40: UIButton:0x1293543b0.Width{id: 32832} rowIndex:9 41: 0x280dc1440.posErrorMarker{id: 32895} colIndex:0 42: 0x280dc1440.negError{id: 32896} rowIndex:1073741845 43: UIButton:0x1293543b0.Height{id: 32827} rowIndex:1073741831 44: 0x280dc3840.posErrorMarker{id: 32897} colIndex:1073741836 45: 0x280dc3840.negError{id: 32898} rowIndex:1073741829 46: UILabel:0x129353a20.Width{id: 32848} rowIndex:10 and another thousand or so lines. this crash occurs after I change the language and open the workout page to start a workout immediately, and sometimes on the second time, I open the workout page.
10
0
5.8k
Feb ’21