SpriteKit (Swift) orientation change - ios

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

Related

Enter full-screen when rotate the device in xamarin form (ios)

I created native IOS av-player in Xamarin forms. every thing works fine but I need video-player should enter full-screen when user rotates the phone. I tried many solution nothing helps me.
currently is tried this
void DeviceRotated(NSNotification notification)
{
string rotaion = UIDevice.CurrentDevice.Orientation.ToString();
if (rotaion == "LandscapeLeft")
{
_playerViewController.ModalPresentationStyle = UIModalPresentationStyle.BlurOverFullScreen;
UIWindow window = UIApplication.SharedApplication.Delegate.GetWindow();
UIViewController rootViewController = window.RootViewController;
_playerViewController.PresentModalViewController(rootViewController, true);
}
}
this didn't help me.
I can understand swift code as well.if any have good answer please share with me.

using swift can we airplay photos on Apple TV programmatically?

I want to build a simple app in iOS using swift which shows the photos of the album in my app and on button click it should airplay on my Apple TV.
I read so many documents and articles but not sure if we can do it for photos. Few have said for audio/video it is possible but not sure about photos.
At least any links or sample code would be helpful.
Thanks
A user should connect the to Apple TV at Control Center via AirPlay:
Then you can use Apple TV as second screen of the app.
Check if the app have external display:
if UIScreen.screens.count > 1 {
// External display is connected ...
}
Create new UIScreen for external window:
if let externalScreen = UIScreen.screens.last {
externalWindow = UIWindow()
externalWindow.screen = externalScreen
configureExternalWindow(externalWindow)
externalWindow.isHidden = false
}
And use it as you want to display photo albums:
// In our Collection View selection callback
if inSingleDisplayMode {
photoViewController.photo = photo
navigationController?.pushViewController(photoViewController, animated: true)
} else {
showOnExternalDisplay(photo)
}
Additional information at WWDC sessions:
Adding Delight to your iOS App
AirPlay and External Displays in iOS apps

How to return to today extension from app

When the user taps the today extension it opens the app where they can modify its settings. But when the app is exited, the user is returned to the home screen. Is there any way I return focus to the today extension so the user can view the changes immediately? Or is this just not possible in iOS?
I recommend making a button to go to the app. Or add transition functionality after applying settings.
like this
var instagramHooks = "instagram://user?username=johndoe"
var instagramUrl = NSURL(string: instagramHooks)
if UIApplication.sharedApplication().canOpenURL(instagramUrl!)
{
UIApplication.sharedApplication().openURL(instagramUrl!)
} else {
//redirect to safari because the user doesn't have Instagram
UIApplication.sharedApplication().openURL(NSURL(string: "http://instagram.com/")!)
}
User can click on the top left button to return if the application has been opened from another application. You can update the data on his return.

How to rename Done button in AVPlayer?

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.

Deep Link in iOS app does not go to Instagram

I've been trying to use deep linking in my iOS app. I've been testing it on an iPad Air running iOS 8.1, and the deep link works fine to open the twitter app, but is not able to open the Instagram app (and indeed, opens the twitter link instead...). Any ideas on why this might be happening? I've used the debugger to make sure the code is following the right paths, but I still can't work out what might be wrong. Could this be happening because the Instagram app is for iPhone instead of iPad?
#IBAction func illustratorButtonPressed() {
var URL = ""
var URLInApp = ""
switch ApplicationConstants.illustratorContact.0 {
case "twitter":
URL = "http://twitter.com/" + ApplicationConstants.illustratorContact.1
URLInApp = "twitter://user?screen_name=" + ApplicationConstants.illustratorContact.1
case "instagram":
URL = "http://instagram.com/" + ApplicationConstants.illustratorContact.1
URLInApp = "instagram://user?username=" + ApplicationConstants.illustratorContact.1
default:
break
}
if UIApplication.sharedApplication().canOpenURL(NSURL(string: URLInApp)!) {
UIApplication.sharedApplication().openURL(NSURL(string: URLInApp)!)
} else {
UIApplication.sharedApplication().openURL(NSURL(string: URL)!)
}
}

Resources