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

UIKit Documentation

Posts under UIKit tag

721 Posts
Sort by:
Post not yet marked as solved
1 Replies
678 Views
VoiceOver sometimes reads decimal numbers in the US locale with a "dot" instead of "point".e.g. 4.29 out of 5 stars -> "four dot twenty nine out of five stars"Is there a way to force it to interpret it as a decimal number?
Posted
by
Post not yet marked as solved
2 Replies
542 Views
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.
Posted
by
Jot
Post not yet marked as solved
5 Replies
8.8k Views
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
Posted
by
Post not yet marked as solved
1 Replies
936 Views
I'm developing an app for virtual headset (cardboard).I want to detect when iphone has been enclosed in the cardboard by using the proximity sensor.Problems:once [[UIDevice currentDevice] proximityState] == YES the screen goes black, while I need to show images.the proximity notification is generated only in portrait mode. I need it (only) in landscape mode.Here my code:- (void)viewDidLoad { [super viewDidLoad]; [[UIDevice currentDevice] setProximityMonitoringEnabled:YES]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proxSensorStateMonitor:) name:UIDeviceProximityStateDidChangeNotification object:nil]; [[UIApplication sharedApplication] setIdleTimerDisabled:YES]; } - (void)proxSensorStateMonitor:(NSNotificationCenter *)notification { if ([[UIDevice currentDevice] proximityState] == YES) { [[UIDevice currentDevice] setProximityMonitoringEnabled:NO]; // Provide content for Cardboard } }
Posted
by
Post marked as solved
11 Replies
38k Views
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).
Posted
by
Post not yet marked as solved
2 Replies
2.1k Views
When I use UIPageViewController with the Spine Location set to Mid and Double Sided and landscape screen orientation, whenever I have an odd number of pages and get to the last page I get the following error:'The number of view controllers provided (1) doesn't match the number required (2) for the requested transition'If I have an even number of pages, it works just fine. How do I handle this error, should I pass an empty page (viewcontroller) when at the end of all pages, and if so, how, or can I handle it in some other more stratightforward way?
Posted
by
Post not yet marked as solved
6 Replies
2.3k Views
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!
Posted
by
Post marked as solved
5 Replies
4.7k Views
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?
Posted
by
Post not yet marked as solved
10 Replies
20k Views
I have a UITableView that I fill with autosizing cells. UITableView setup is fairly simple:tableView.estimatedRowHeight = 70 tableView.rowHeight = UITableViewAutomaticDimensionExactly like Apple recommends here: https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithSelf-SizingTableViewCells.htmlTo enable self-sizing table view cells, you must set the table view’s rowHeight property to UITableViewAutomaticDimension. You must also assign a value to the estimatedRowHeight property. As soon as both of these properties are set, the system uses Auto Layout to calculate the row’s actual height.When configuring a cell I also disable/enable some constraints to achieve the needed look. That’s where things get interesting. Cell layout is not updated until the cell is reused. Literally. You can call layoutIfNeeded(), setNeedsLayout(), layoutSubviews() or any other method there is, there is no way you will force the cell to update its layout.All other aspects work pretty good: labels do change their text, you hide/unhide the views, but layout is stuck until the cell is reused.You can find the sample project with the bug here: https://www.dropbox.com/s/vqg0gw0a8ycziyq/ReusedCellBug.zip?dl=0Question: what causes it and how to avoid this behavior?P.S. After playing around I found out that if I completely remove `tableView.estimatedRowHeight = 70`, then layout works as expected, but trying to use autosizing cells without estimatedRowHeight leads to table view putting height constraint on cell's content view (height equals to 43.5 point). In error logs this constraint is the famous'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fd63d508490.height == 43.5 (active)And because my cell's height is not equal to 43.5 points, auto layout decides that this height constraint is more important than my cell's layout and fits my cell content in 43.5 points.So I can't use estimatedRowHeight because it breaks auto layout, but without it my layout also gets broken.how can I safely deprioritize this UIView-Encapsulated-Layout-Heightconstraint? Is there any way I can get autosizing cells without using estimatedRowHeight?
Posted
by
Post not yet marked as solved
10 Replies
52k Views
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.
Posted
by
Post not yet marked as solved
6 Replies
5.7k Views
Call Kit behaviors depending on lock state of the device.I am working a new iOS VOIP app and while an experienced iOS developer, I have not done VOIP in the past so a lot of this is new to me. I’m looking for clarification as to differences in how CallKit handles an incoming call depending on the lock state of the device and confirmation as to the reasoning behind it.My Assumption Based on ObservationIf my phone is locked and an incoming call is being handled by CallKit (as via my experience using WWDC’s Speakerbox demo) the user will see a system “Incoming Call” view with a “Slide to answer” widget. Upon sliding they will have an active audio connection with the caller and the UI will change to a view I’d call the “Active Call” view. This view presents a button to visit the app and potentially a video button if the app has advertised this as a video call. When the user taps the app or video button they are made to authenticate using a passcode or TouchID. Once authenticated they are brought to the app.The behavior for an incoming call with an unlocked phone is much different. Instead of the “Incoming Call” view with the slider, we now have two buttons: Accept or Decline. Upon tapping Accept the user is directed immediately to the VOIP app – skipping the system provided “Active Call” view.QuestionsShould I assume the primary reason CallKit responses with the system “Active Call” view instead of my own app on a locked iOS device is for security concerns? It’s a conclusion we’ve come up with based on other behaviors but I have yet to see Apple document it with any detail.If I had an app that was primary considered a video conferencing app, is there any way to better enter the video call experience in a locked device scenario? It would seem not – BUT then I look at FaceTime, and when my device is receiving a FaceTime call the Incoming Call view actually shows my active front facing camera and then immediately takes me to a FaceTime experience (regardless if the device is locked or not). I assume these behaviors are a special case only available to FaceTime but I welcome feedback to point me in the right direction.I notice that when I accept a call on an unlocked phone on Speakerbox there is a slightly jarring display of the active call view right before my app is brought to the front. Is this something I can help avoid in my own code?
Posted
by
Post not yet marked as solved
6 Replies
6.3k Views
I'm struggling to figure out how to rename an instance of a UIDocument subclass in an iCloud folder. I've tried saving the document with the new URL…func renameDocument(to name: String) { let targetURL = document.fileURL.deletingLastPathComponent().appendingPathComponent(name) .appendingPathExtension("<extension>") document.save(to: targetURL, for: .forCreating) { success in guard success else { // This always fails return } // Success } }…but this fails with…Error Domain=NSCocoaErrorDomain Code=513 "“<new-file-name>” couldn’t be moved because you don’t have permission to access “<folder>”." UserInfo={NSSourceFilePathErrorKey=/private/var/mobile/Containers/Data/Application/1A9ACC2B-81EF-4EC9-940E-1C129BDB1914/tmp/(A Document Being Saved By My App)/<new-file-name>, NSUserStringVariant=( Move ), NSDestinationFilePath=/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/<folder>/<new-file-name>, NSFilePath=/private/var/mobile/Containers/Data/Application/1A9ACC2B-81EF-4EC9-940E-1C129BDB1914/tmp/(A Document Being Saved By My App)/<new-file-name>, NSUnderlyingError=0x1c4e54280 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}…and just a simple move…func renameDocument(to name: String) { let targetURL = document.fileURL.deletingLastPathComponent().appendingPathComponent(name) .appendingPathExtension("<extension>") do { try FileManager.default.moveItem(at: document.fileURL, to: targetURL) } catch { // This always fails } // Success }…which fails with…Error Domain=NSCocoaErrorDomain Code=513 "“<old-file-name>” couldn’t be moved because you don’t have permission to access “<folder>”." UserInfo={NSSourceFilePathErrorKey=/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/<folder>/<old-file-name>, NSUserStringVariant=( Move ), NSDestinationFilePath=/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/<folder>/<new-file-name>, NSFilePath=/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/<folder>/<old-file-name>, NSUnderlyingError=0x1c4c4d8c0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}Both of these work fine for local files, and renaming iCloud files works OK in the UIDocumentBrowserViewController root view controller. My guess is that there's some permission missing somewhere that allows the app to write to iCloud folders.For info, the info.plist contains all the following keys…LSSupportsOpeningDocumentsInPlaceNSExtensionFileProviderSupportsEnumerationUISupportsDocumentBrowser
Posted
by
Post not yet marked as solved
2 Replies
5.5k Views
In my app I have a second UIWindow that appears above the main window in order to present a small floating view controller that appears above other view controllers in the app. Touches pass through the top window to the lower (main) window. Whenever the main window presents a UIAlertController the alert appears behind the floating view controller in my top window. I was under the impression that alerts are presented in their own window with a window level of UIWindowLevelAlert, which should place them above any controller that belongs to a window at UIWindowLevelNormal (which is the level of both my main window and top window).How can I get alerts presented by my lower (main) window to appear above controllers in my overlay window?
Posted
by
Post not yet marked as solved
3 Replies
1.3k Views
I have a collection view with two sections. You can drag cells between both sections. However, if you drag from a section with only one cell to the other, you then cannot drag back into the empty section. It seems trivial since I cannot find anything mentioning this issue, what am I missing here?
Posted
by
Post not yet marked as solved
2 Replies
8.3k Views
I have an app with an action extension that takes a photo (the app only) or grabs a photo from a 3rd-party app or within the app itself, e.g. Photos, adds an imprint, e.g. date, and then adds a new photo to an album, Camera Roll. The app itself has no issue doing that for any photo in any app (lots of memory). But the extension crashes when the original photo is over ~8mb with some hard memory limit (120mb). But when I watch the memory use, it stays around 20mb, and when I initiate the stamped overlay, it briefly goes to 80mb, and then back down to 20mb and then crashes.The error is EXC_RESOURCE RESOURCE_TYPE_MEMORY (limit=120 MB, unused=0x0). Finally, I found that problem resides in a method where I add the imprint by drawing the original image in a graphic context using drawInRect: and then drawing the overlay into the same context and converting it to a UIImage and returning that to the caller. The app crashes at drawInRect: with vImage`_ERROR_Buffer_Write__Too_Small_For_Arguments_To_vImage__CheckBacktrace:With larger megapixel phones, this has caused me to remove my app from the App Store, and It sure doesn't seem like I've broken any programming rules.Does anyone know how to fix this kind of issue/crash?
Posted
by
Post not yet marked as solved
3 Replies
6.3k Views
Hi,When dragging a view inside UIScrollView using UIDragInteraction/UIDropInteraction, the scroll view *automatically* scrolls as you drag your view near the edge of the screen. How can you prevent this behavior? I want to disable *only* the automatic scrolling, not the scrolling itself, so that the user can scroll with the second finger if he so chooses. I know I can disable scrolling using isScrollEnabled, but this will also disable the user-initiated scrolling. Thanks.
Posted
by
Post marked as solved
4 Replies
11k Views
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?
Posted
by
Post not yet marked as solved
2 Replies
1.4k Views
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.
Posted
by
Post not yet marked as solved
15 Replies
7.2k Views
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
Posted
by