UIDocumentMenuViewController buttons not doing anything - ios

So I'm testing out Apple's new Document Provider extension. I'm trying to open up a UIDocumentMenuViewController up, and that part is working. But when I try to click on one of the items it presents, it just cancels the action sheet. This happens even when I click on the iCloud item, which is there by default. My code for presenting the controller is as follows:
let type_data = kUTTypeData.__conversion()
let documentMenuViewController = UIDocumentMenuViewController(documentTypes: [type_data], inMode: UIDocumentPickerMode.Import)
navigationController.presentViewController(documentMenuViewController, animated: true, completion: nil)
Anyone know why this is happening?

You need to set the delegate on the UIDocumentMenuViewController. Then implement the -documentMenu:didPickDocumentPicker: delegate method. Then you can go ahead and present the documentPicker that was selected.
func documentMenu(documentMenu: UIDocumentMenuViewController!, didPickDocumentPicker documentPicker: UIDocumentPickerViewController!) {
documentPicker.delegate = self
self.presentViewController(documentPicker, animated: true, completion: nil)
}
There is a simple example of this here in Apple's guide.

Take a look at the NewBox Apple sample code and you'll see the step you are missing. Can't provide the actual answer here as iOS 8 is still under NDA.

Related

How can I get the video from RPScreenRecorder or add a share button?

I'm recording video using RPScreenRecorder.shared().startRecording. However, I want to let the user share the video from within the app. This is the code that stops recording and previews the video in a view controller and gives the user the option to save to photos or cancel.
I cannot figure out how to grab the video from the view controllers view. When I dug into the subviews: preview.view.subviews.first!.subviews.first! There's a view of type: UIRemoteView with no subviews.
Is it possible to grab the video? Or better yet, is there a way to show a UIActivityViewController to allow the user to share the video?
for macOS I could do preview.mode = .share, but for iOS this is not available.
RPScreenRecorder.shared().stopRecording { preview, error in
guard let preview = preview else { return }
self.present(preview, animated: true, completion: nil)
}
There is a share button but it is not visible, if view controller is not presented fullscreen, I think this is a bug related to PRPreviewViewController.
You can change modalTransitionStyle and see share button.
RPScreenRecorder.shared().stopRecording { preview, error in
guard let preview = preview else { return }
preview.modalPresentationStyle = .overFullScreen
self.present(preview, animated: true, completion: nil)
}

Presenting UIActivityViewController casue screen/ui freeze

I try to present UIActivityViewController to my app users but when I do my app sometimes, not always but often, freeze. What I mean is that activity view is on screen but do not respond to user interaction at all. You can't scroll available items, you cannot select any activity item, you cannot click Cancel etc
The way I invoke it is very simple and basic:
func presentSystemShareNotification(notification : Notification) {
if let vURL = notification.userInfo?["videoURL"] {
let activityViewController = UIActivityViewController(activityItems: [vURL], applicationActivities: nil)
activityViewController.excludedActivityTypes = [UIActivityType.airDrop]
naviController.topViewController?.present(activityViewController, animated: true, completion: {() in
print("done presenting")
})
}
}
When ui freezed completion handler is not called. But app itself works, timers are called, ui manipulation like view alpha decrese works and you can see view dim. Any ideas or at least tips what could cause this behavior? Thank you in advance.

How to close SFSafariViewController automatically when reaching a certain page

I want to close SFSafariViewController automatically upon reaching the "thank you" page of the Dropbox site after the user uploads something; it needs to automatically dismiss. How can I do that?
Here is what I have so far:
#IBAction func Singles5(_ sender: Any) {
let safariVC = SFSafariViewController(url: NSURL(string: "https://www.dropbox/Upload")! as URL)
self.present(safariVC, animated: true, completion: nil)
safariVC.delegate = self
}
One way I can think of is using the Custom URL scheme. You can specify your app's custom URL in the callback parameter of Dropbox (if Dropbox has callback). So when the user has finished uploading his/her file, dropbox executes the callback. In this case your app will receive the callback, with any parameters have you specified. This will call the function application(app, open, options)->Bool in your AppDelegate. Now, you can use a reference to the ViewController which presents the SFSafariViewController and call SafariViewController.dissmissViewController().

MPMediaPickerController shows an empty screen on iOS10

I am trying to port my apps to iOS 10, including the visualization of a MPMediaPickerController by means of the following code:
#IBAction func handleBrowserTapped(_ sender: AnyObject){
let pickerController = MPMediaPickerController(mediaTypes: .music)
pickerController.prompt = NSLocalizedString("Add pieces to queue", comment:"");
pickerController.allowsPickingMultipleItems=true;
pickerController.delegate=MPMusicPlayerControllerSingleton.sharedController();
self.present(pickerController, animated:true, completion:{
MPMusicPlayerControllerSingleton.sharedController().storeQueue()
})
}
Yet all that appears on the screen is a full white screen with no back buttons or other, differently from the previous iOS versions. The block is called and so the picker's presentation seems to succeed. What could be the problem?
Add Key-value to Plist :
<key>NSAppleMusicUsageDescription</key>
<string>$(app Name) uses music</string>
The issue was fixed by the latest beta now asking for an authorisation to access the iTunes library.

safariViewController debugging - URL not loading

I'm using SFSafariViewController in an iOS 9 app I'm building using Swift 2.
I am trying to open a URL which fails for some reason. EVery other URL I've tried works, except for this one:
http://www.ctvnews.ca/sci-tech/33-engineers-to-be-recognized-at-sci-tech-oscars-1.2730223
The URL is fine in regular mobile Safari in the simulator, on my iPhone, my iPad, and in any desktop browser. It is just when I try accessing it via Swift in this app that it fails.
Code is as follows:
func openInSafari(URLtoOpen: String) {
print("Trying to openURL: " + URLtoOpen)
let safariVC = SFSafariViewController(URL:NSURL(string: URLtoOpen)!, entersReaderIfAvailable: false)
safariVC.delegate = self
self.presentViewController(safariVC, animated: true, completion: nil)
}
func safariViewController(controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) {
// SFSafariViewController will present an error message in the browser,
// but in this case we will dismiss the view controller and present our
// own error alert.
if didLoadSuccessfully == false {
controller.dismissViewControllerAnimated(true, completion: { [unowned self] () -> Void in
let alert = UIAlertController(title: "Could Not Load", message: "The URL could not be loaded.", preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "Okay", style: .Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
})
}
}
This code works fine, and, as I said, other URLs load just fine. What I really need is just a way to more verbosely debug what safariViewController is encountering that is causing it to fail.
The didLoadSuccessfully == false line doesn't really appear to offer much more debugging options to get a sense of what went wrong.
In other words, how do I debug this? I can't seem to find anything in Apple's docs that would explain what to check in case of a loading error.
Please help!
Thanks.
The SFSafariViewController is voluntarily shielded from the app (I wouldn't be surprised if it's actually a different process), and there's very little information shared with the app for privacy and security reasons.
What you could try is loading the same based in an UIWebView or WKWebView (which gives you a lot more feedback, but doesn't share cookies or passwords with Safari) to see what happens then.

Resources