using swift can we airplay photos on Apple TV programmatically? - ios

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

Related

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.

Is it okay to download data directly to watch OS from server

So I'm trying to make a watchOS app for a music streaming app, and I found an example pretty much close to what I'm going to make.
(https://github.com/belm/BaiduFM-Swift)
But It seems like the project is kinda outdated. According to the codes below, watch extension is getting required datas like sound, images via HttpRequest. From what I read, watchOS 3 supports Background Connectivity, (which enables app to transfer data more efficiently) and Apple encourages developers to process and get data from the main app.
What is right way to do it? Is there any good example to see?
// play song method in interface controller
HttpRequest.getSongLink(info.id, callback: {(link:SongLink?) -> Void in
if let songLink = link {
DataManager.shareDataManager.curSongLink = songLink
DataManager.shareDataManager.mp.stop()
var songUrl = Common.getCanPlaySongUrl(songLink.songLink)
DataManager.shareDataManager.mp.contentURL = NSURL(string: songUrl)
DataManager.shareDataManager.mp.prepareToPlay()
DataManager.shareDataManager.mp.play()
DataManager.shareDataManager.curPlayStatus = 1
Async.main{
self.songTimeLabel.setText(Common.getMinuteDisplay(songLink.time))
}
HttpRequest.getLrc(songLink.lrcLink, callback: { lrc -> Void in
if let songLrc = lrc {
DataManager.shareDataManager.curLrcInfo = Common.praseSongLrc(songLrc)
//println(songLrc)
}
})
}
})

ReplayKit sharing video to facebook has no commentary

I'm recording a video with commentary, and I'm using replaykit. Everything is working fine on iPhone, but when I share to facebook, my videos has no sound at all. I've downloaded a video to my mac and it's m4v with sound. But when I'm trying to share it from my mac to facebook it doesn't has sound too. On youtube it works very good. Not sure is there any way I can fix it? Can I record a screen and commentary without replaykit and pass app review?
Start:
RPScreenRecorder.shared().isMicrophoneEnabled = true
RPScreenRecorder.shared().startRecording { (error) in
if error == nil {
//TODO: show RECORDING view
print("start recording")
}
}
Stop:
RPScreenRecorder.shared().stopRecording { (previewViewController, error) in
if let previewVC = previewViewController, error == nil {
previewVC.previewControllerDelegate = self
self.present(previewVC, animated: true, completion: nil)
}
}
Seems to be Fixed by Apple
(on the latest IOS 11 Beta's update)
Ofir Malachi I will write it as an answer, I used some parts of Spitfire library, I'm doing a screenshot of this part of the screen I want to "record" every 0.1 second. I'm merging those images to a video. In the same time I'm recording audio. At the end I've got "output.mov" and "recording.m4a". I'm using AVAssetExportSession to merge it asynchronously to the mp4 file.

Call from App Extension (iMessage)

I'm working on iMessage app extension for my app and i was wondering if its possible to initiate a phone call from App Extension?
I tried using the following code but it takes me (deeplink) to containing app.
cell.didTapCallNowButton = { cell in
if let phoneNumber = cell.Model.phone,
let url = URL(string: "telprompt:\(phone)") {
self.extensionContext?.open(url, completionHandler: nil)
}
}
Here is the answer from pdm 'Apple Staff' on Apple developer forum:
No. iMessage apps can only open URLs in their parent app.
https://forums.developer.apple.com/message/174112#174112

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