MPMediaPickerController shows an empty screen on iOS10 - ios

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.

Related

MFMailComposeViewController behaves differently in iOS 13 simulator and device

I'm trying to display MFMailComposeViewController in an app.
if MFMailComposeViewController.canSendMail() {
let mailComposeViewController = MFMailComposeViewController()
mailComposeViewController.navigationBar.tintColor = .white
mailComposeViewController.mailComposeDelegate = self
mailComposeViewController.setToRecipients(["support#gmail.com"])
mailComposeViewController.setSubject("Feedback")
present(mailComposeViewController, animated: true)
} else {
print("This device is not configured to send email. Please set up an email account.")
}
In iOS 12, it shows up without an issue. In both simulator and device.
But when I run the same project on a device running iOS 13, it looks like this.
The navigation bar color is gone. Also the send button is also invisible.
So I added mailComposeViewController.navigationBar.backgroundColor = .mv_primary but it still doesn't show on the device. Strangely the background color shows in the simulator.
However there's a strange behavior. The MFMailComposeViewController immediately dismisses by itself when I run it in the simulator.
The following error also shows up in the Xcode console.
[Common] [FBSSystemService][0x5f27] Error handling open request for
com.apple.MailCompositionService: {
userInfo = {
FBSOpenApplicationRequestID = 0x5f27;
}
underlyingError = ; } 2019-11-01
14:40:05.214158+0530 MailCompose[11289:262267] [Assert] Connection
request invalidated without resuming our _serviceSessionConnection.
This is an error. 2019-11-01 14:40:05.216901+0530
MailCompose[11289:262054] [General] #CompositionServices
_serviceViewControllerReady: NSError Domain=_UIViewServiceInterfaceErrorDomain Code=0
I guess the weird dismiss error is a Xcode bug. But how do I fix the background color and the send button not showing up in the device?
This is how I set all the navigationbar related styles.
UINavigationBar.appearance().barTintColor = .mv_primary
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
if #available(iOS 11.0, *) {
UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
}
Demo project
Add this line of code before present it. It will work normal. This a change in iOS 13
mailController.modalPresentationStyle = .fullScreen
The reason why the Mail composer dismisses immediately is because you can't actually send an email from the simulator. The implementation is different from iOS itself.
What I guess is happening here is that while the simulator implementation uses just some normal UI elements, the MFMailComposeViewController on native iOS is actually hosted like UIDocumentPickerViewController or UIActivityViewController. This means screenshots and trying to traverse the view tree is impossible, because the view is not an actual part of your application. They do that because these controllers contain user private information. Hosted view controller do NOT allow for customization, and do not comply with your global UINavigationBar.appearance(). This would explain why it does show up in the simulator and not on your native device.
This is new UI Style from iOS 13. You can disable it in Storyboard or set manual.
Presenting modal in iOS 13 fullscreen

Razor pay is not redirecting to checkout page, why?

I am using,
*Xcode - 10.2
*Swift language version - swift 5
*RazorPay framework version - 1.1.1 (pod 'razorpay-pod', '1.1.1')
My problem is when I am calling this,
razorpay.open(options, displayController: self)
It gives me an unexpected error (code - 1) with
/Users/travis/build/razorpay/razorpay-ios/RazorpayIOS/CheckoutOtpelf/Classes/RazorpayCheckoutVC.swift deinitialized
Solutions I tried were,
Github community says to hide navigation bar before calling open function(https://github.com/razorpay/razorpay-pod/issues/42).
Used multiple framework version of razor pay
Tried with swift 4.2 also
I have cleaned my project, deleted derived data and rebuilt it.
Here's my code
import Razorpay
class controller: RazorpayPaymentCompletionProtocol{
private var razorpay: Razorpay!
override func viewDidLoad() {
super.viewDidLoad()
razorpay = Razorpay.initWithKey("test_key", andDelegate: self)
}
func openRazorPay(){
let options = [
"amount" : "12.00"
]
self.navigationController?.isNavigationBarHidden = true
razorpay.open(options, displayController: self)
}
func onPaymentSuccess(_ payment_id: String) {
print("success")
}
func onPaymentError(_ code: Int32, description str: String) {
print("Failure")
}
}
This framework supports Android, but not for iOS. I want to get the payment flow. If anyone has any solution, share with me.
As I face the same issue......
What I did differently is I take a static amount value 100 and pass the other data as it is.....and I make payment process...it works...open the payment window.
If your amount value less than 100 then it happens...as per doc, the amount we are assigning in the param consider it as a paisa....Try with this one and you will get expected result..
Here what the amount you are passing, make a multiply with 100 e.g 1 x 100. The internal processing will be count it as INR 1, but their calculation is consider it as paisa. So you passed value 100 means 100 paisa and in payment window it will show INR 1.
I was facing the same issue And All of the parameters which i was sending to the options was right.
But the issue was when we try to open RazorPay screen for payment was getting the issue of the RazorpayCheckoutVC.swift deinitialized
In my case my parent viewController was presented so i just changed the navigation code of present to the push and then it worked.
So as per my understanding it should be as
NavigationController -> Push ViewController -> RazorPaycheckoutVC.

Open App From Widget IOS with Swift

How I can open my App from the Today Widget with Swift ?
I just want to pressed the Widget and than i would like to open my App.
I got right now a button on my whole view the button is clear.
But that don't work for me:(
I need Help:)
#IBAction func launchApp(sender: AnyObject) {
var url: NSURL = NSURL.URLWithString("AffordItLauncher://")
self.extensionContext?.openURL(url, completionHandler: nil)
}
In your info.plist you need to add the following:
And make sure that your app name is the same as the one in your url. In your case, it should be AffordItLauncher

UIDocumentMenuViewController buttons not doing anything

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.

How to reduce the MPMediaPickerController loading time?

In my project I am using MPMediaPickerController to pick a file from the device music library. I am using following piece of code for displaying the media picker.
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
mediaPicker.delegate = self;
mediaPicker.prompt = #"Select a personal message";
[self presentViewController:mediaPicker animated:NO completion:nil];
Everything is working fine,but the MediaPickerController is taking a couple of seconds (2 to 3 sec) for showing the music library. Is there any way to reduce this loading time of MPMediaPickerController. This delay after clicking the upload button is realy a bad user experience.
There's nothing you can do. If there is a lot of music, it takes time to survey all of it and prepare the controller, and that's all there is to it. This is no different from the delay the first time the user tries to use the Music app. You might be able to reduce the amount of material shown by turning off showsCloudItems, but even that might not help.
The best you can do is probably to try to cover the delay psychologically, i.e. by giving the user something to see, such as a spinning activity indicator, until everything is in place. I have not tried this with a MPMediaPickerController, however (I've done it with my own home-built music library exploration interface, which has the same delay issues).
I noticed my MediaPickerController was very slow as well (in my current project, using Swift 2.2), even though it was pretty quick earlier in the project (and most of what I have added since has been networking code).
In my code, I was instantiating the MPMediaPickerController only when the user tapped my "Find a song" button. By creating the instance of MPMediaPickerController at the time of the main view loading (I placed it in my class declaration, outside of viewDidLoad), I was (somehow) able to bring that load time back down to less than a second (whereas it sometimes didn't even show up, when I instantiated the MPMediaPickerController at the last possible second).
TLDR: write this:
import UIKit
import MediaPlayer
import MobileCoreServices
class SomeViewController: UIViewController, MPMediaPickerControllerDelegate {
var mediaPickerController = MPMediaPickerController(mediaTypes: .AnyAudio)
func viewDidLoad() {
mediaPickerController.delegate = self
mediaPickerController.prompt = "Select a song that you like"
}
#IBAction func buttonWasTapped(sender: AnyObject) {
self.presentViewController(mediaPickerController, animated: true, completion: nil)
}
}
Instead of this: (notice how I only instantiate mediaPickerController once my button is tapped.
import UIKit
import MediaPlayer
import MobileCoreServices
class SomeViewController: UIViewController, MPMediaPickerControllerDelegate {
func viewDidLoad() {
}
#IBAction func buttonWasTapped(sender: AnyObject) {
var mediaPickerController = MPMediaPickerController(mediaTypes: .AnyAudio)
mediaPickerController.delegate = self
mediaPickerController.prompt = "Select a song that you like"
self.presentViewController(mediaPickerController, animated: true, completion: nil)
}
}
As matt suggested, a spinning activity indicator can really help the user experience as it reassures the user that it's working and it hasn't crashed. I used MBProgressHUD for this when loading a track from the music library.

Resources