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
616
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
0
9.2k
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.1k
Oct ’16
Launch Screen Image not Updating!!!
Hi, I am a iOS developer. I have an iOS app currently running in Appstore. I am in the process of updating the app’s Launch image. Previously the app had a Launch screen image which was added in LaunchScreen.xib and in the update I want to change the Launch screen image. If I try to use the same xib with different image, the app takes the previous image as Launch screen image. I also tried using completely new xibs and image assets but the splash screen becomes a blank white screen in this case. Any helps to fix this will great.
10
2
53k
Nov ’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
0
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.5k
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.6k
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.4k
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.3k
Aug ’20
NSDiffableDataSourceSnapshot doesn't call Hashable methods if ItemIdentifierType is class
I have a collection view with UICollectionViewDiffableDataSource, which has class PHAssetVisualAssetsPickerItem as it’s ItemIdentifierType. When I create instance of NSDiffableDataSourceSnapshot with the same items that dataSource already has, and then apply it, I see that collection view blinks even tho nothing changed. It actually blinks no matter what new snapshot is. My investigation led to a fact that methods == (Equatable) and hasher(into:) (Hashable) are not called on items if items are classes. If I change them to structs, methods are called, dataSource understands what to do, nothing blinks. https://www.icloud.com/iclouddrive/0vnB3auwp0ShEvPQmpVOAy6fg#ApplySnapshotIndexPaths Here is the code where you can simply change HashableType to either class or struct and see that collectionView update looks different when you tap button.
8
0
3.3k
Aug ’20
iOS14: Set text color in UIDatePicker
I am using Xcode Version 12.0 (12A7208) with… picker.preferredDatePickerStyle = .wheels I have tried: picker.setValue(UIColor.white, forKeyPath: "textColor") // crash and … picker.tintColor = UIColor.white // no change and … UILabel.appearance(whenContainedInInstancesOf: [UIDatePicker.self]).textColor = UIColor.white // no change
4
0
5.4k
Sep ’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
3k
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.5k
Dec ’20