How to rename Done button in AVPlayer? - ios

I'm developing an app in Swift 3.0 that gives users the chance to stream TV channels online. It is restricted to Italy at the time, so I'm trying to translate every button in the app in Italian... but I'm having problems for the Done button (and the "Live streaming" field) at the top of the AVPlayer screen that appears whenever the user chooses a channel to stream. I'm sure there's a way to edit them, because when I open a stream in Safari, the Done button is correctly displayed as "Fine" and "Live streaming" becomes "Trasmissione in diretta"... I'd like to see them this way too but I have no idea of the way to reach that goal.
I haven't made any specific class for the player, just created a segue from the storyboard to the AVPlayerController, and I manage streams entirely from the table view that contains the channels; here's my significant code:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "guardaCanale" {
let destinazione = segue.destination as! AVPlayerViewController
if let cellaCanaleSelezionata = sender as? CanaleTableViewCell {
let indexPath = tableView.indexPath(for: cellaCanaleSelezionata)!
let canaleSelezionato = ritornaIlCanaleCorretto(indexPath: indexPath)
let url = URL(string: canaleSelezionato.urlCanale)
if let streamingURL = url {
destinazione.player = AVPlayer(url: streamingURL)
// Il do-try-catch seguente serve per far funzionare l'audio dell'app anche se l'iPhone è in modalità silenziosa; togli il blocco per fare in modo che l'app non produca audio se l'iPhone è in modalità silenziosa
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
} catch {
print("Errore: non riesco a riprodurre l'audio se iPhone è in modalità silenziosa.")
}
destinazione.player?.play()
}
}
}
}
Anyone can help me please? I don't want to modify the Done button behavior, just change its visible name onscreen... hope someone could help me! Thank you so much! :)

It sounds like you haven't properly setup your app for Italian localization.
Translation for Apple provided UI elements is based on the language of the device and whether or not your app supports that language. If you change the devices language to Italian, this is what it should show automatically.
I'd suggest reading Apple's Localization Documentation to make sure you are properly setting up you app so the system knows it's localized for Italian.

Related

How can I switch between 11 pro cameras using AVFoundation in Xcode

I've just started out learning Swift in Xcode and am creating a simple camera App to get up and running. I have a button that switches between the front and back facing cameras working but want to add the option to also switch between the Tele and the Ultra Wide lens on the iPhone 11 Pro.
I have created the functions to run a new CaptureSession for each lens (if detected) but was just wondering how I can call these functions to UIbutton function
The thing that's got me scratching my head is the if statement used to switch between the front and back camera says if input.device.position == .back {
This only specificities if it's front or back, not the lens itself. What would be an efficient way to make the button then Change from the front to wide, the Tele, the Ultra Wide and back to the front each time the button is pressed?
Apologies for any misuse of terminology, I'm very new to coding in Swift. Thank you!
{
guard let CurrentCameraInput: AVCaptureInput = CaptureSession?.inputs.first else {
return
}
if let input = CurrentCameraInput as? AVCaptureDeviceInput
{
if input.device.position == .back {
SwitchToFrontCamera() }
if input.device.position == .front {
SwitchToBackCamera()
}
}
}
Welcome!
Check you this initializer for AVCaptureDevice. You can specify the DeviceType you want to use, like .builtInUltraWideCamera or .builtInTelephotoCamera.
You can use a AVCaptureDevice.DiscoverySession to get a list of all capture devices available to your app.

Why doesn't my iOS (Swift) app properly recognize some external display devices?

So I have an odd issue and my google-fu utterly fails to even provide me the basis of where to start investigating, so even useful keywords to search on may be of use.
I have an iOS application written in swift. I have a model hooked up to receive notifications about external displays. On some adaptors, I'm able to properly detect and respond to the presence of an external display and programatically switch it out to be something other than a mirror (see code block below). But with another adaptor, instead of just 'magically' becoming a second screen, I'm asked to 'trust' the external device, and it simply mirrors the device screen. Not the intended design at all.
func addSecondScreen(screen: UIScreen){
self.externalWindow = UIWindow.init(frame: screen.bounds)
self.externalWindow!.screen = screen
self.externalWindow!.rootViewController = self.externalVC
self.externalWindow!.isHidden = false;
}
#objc func handleScreenDidConnectNotification( _ notification: NSNotification){
let newScreen = notification.object as! UIScreen
if(self.externalWindow == nil){
addSecondScreen(screen: newScreen)
}
}
#objc func handleScreenDidDisconnectNotification( _ notification: NSNotification){
if let externalWindow = self.externalWindow{
externalWindow.isHidden = true
self.externalWindow = nil
}
}
The worst issue here is that because I'm connecting to an external display to do this, I can't even run this code through the debugger to find out what is going on. I don't know where to even begin.
Any ideas?
Edit:
Thanks to someone pointing out wifi debugging, I can tell you my notifications are firing off, but they're both firing at the same time, one after the other, when the external adaptor is disconnected.

How to display AdMob banner in AVPlayer?

I'm working on an app to watch live streams. It is based on a table view and I'd like to offer it for free with ads (with the chance to buy the "Pro version" with in-app purchase). I managed to insert AdMob banners in the table view, but I'd like to insert small banners in the video streams too. I use AVPlayer to display streams and I know there's a method called contentOverlayView that allows to insert a custom view that stays visible when the video is playing, so I thought I have to use that method to display this banner, but I wasn't able to. The following code sets the player and it works perfectly, but the code I added to show the banner seems to be totally useless (i still see the video perfectly but no banner is displayed):
func allestisciPlayer(indexPath: IndexPath, destinazione: AVPlayerViewController) {
// Ricava il canale corretto per mezzo della funzione apposita
let canaleSelezionato = ritornaIlCanaleCorretto(indexPath: indexPath)
// Prende il percorso giusto per lo streaming, poi crea il player nella destinazione
let url = URL(string: canaleSelezionato.urlCanale)
if let streamingURL = url {
destinazione.player = AVPlayer(url: streamingURL)
// Il do-try-catch seguente serve per far funzionare l'audio dell'app anche se l'iPhone è in modalità silenziosa; togli il blocco per fare in modo che l'app non produca audio se l'iPhone è in modalità silenziosa
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
} catch {
print("Errore: non riesco a riprodurre l'audio se iPhone è in modalità silenziosa.")
}
let bannerView = GADBannerView()
bannerView.adUnitID = "ca-app-pub-xxxx/xxxx"
bannerView.rootViewController = self
let request = GADRequest()
request.testDevices = ["xxxx"]
bannerView.load(request)
bannerView.bounds = CGRect(x: 0, y: 0, width: 320, height: 50)
destinazione.contentOverlayView?.addSubview(bannerView)
// Infine avvia il player
destinazione.player?.play()
}
}
Where do I get wrong? I also tried to use this code in the prepareForSegue method and even by overriding the AVPlayerViewController's viewDidLoad method but still without success... anyone can help me please?
EDIT: I found out it wasn't that difficult :) I simply create a new banner (different from the existing one in the table view) and display it by creating another UIView, adding the banner as subview to this new view and finally adding the new view as subview to my AVPlayerViewController. I didn't manage to display banner using the contentOverlayView method, but I read somewhere that even if I would be able to display the ad using it, I wouldn't be able to click it cause user touches are disabled with the contentOverlayView content. Thank you anyway :)
This is not correct way to initialize the ad. You should initialize it in appdelegate, then you should be able to display the ad freely anywhere you want.

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.

SpriteKit (Swift) orientation change

I am making/made a game in landscape orientation and have a Facebook and a twitter button in the main menu to either open the app or Safari.
The problem I have is that the app or safari opens up in portrait mode and when I switch back to my game it briefly shows everything in portrait before changing back to landscape. It also shows you a multitasking preview in portrait.
It is not a big deal but obviously for that brief 1-2 seconds the game is in portrait mode everything is squashed and it looks sort of ugly and unprofessional. This only happens when you use those 2 social media buttons, when you just switch to a portrait app yourself via multitasking the game will stay in landscape upon return.
I have being trying to figure it out but I cannot find anything, especially for swift. Any help would be much appreciated. Thanks
PS. This is the code I used for the social media parts, I think its pretty straight forward and boiler plate.
//MARK: - Load Social Media
func loadFacebook() {
var appURL = NSURL(string: "APP ID HERE")
var webURL = NSURL(string: "WEB ID HERE")
if(UIApplication.sharedApplication().canOpenURL(appURL!)) {
// App
UIApplication.sharedApplication().openURL(appURL!)
} else {
// Safari
UIApplication.sharedApplication().openURL(webURL!)
}
}
func loadTwitter() {
var appURL = NSURL(string: "APP ID HERE")
var webURL = NSURL(string: "WEB ID HERE")
if(UIApplication.sharedApplication().canOpenURL(appURL!)) {
// App
UIApplication.sharedApplication().openURL(appURL!)
} else {
// Safari
UIApplication.sharedApplication().openURL(webURL!)
}
}
see here for answer as this is still an issue where there is not a lot of information about.
Swift sprite kit landscape only forced into portrait

Resources