I am trying to use AVAudioSession in Xcode for my Mac OS application, but Xcode when I try using this code:
import Foundation
import AVFoundation
var recordingSession: AVAudioSession!
Xcode gives me a error: "Use of undeclared type 'AVAudioSession'"
I have correctly linked the AVFoundation framework to my project, but it still gives that error.
Upon looking into the current AVFoundation framework, I found that AVAudioSession header does not exist inside of AVFoundation. I have looked all over Google and have found no evidence of anybody else having this issue, and Apple has not deprecated AVAudioSession.
Is AVAudioSession residing in some other framework?
It looks like AVAudioSession is only available on iOS. Here is the AVFoundation programming guide for Mac:
https://developer.apple.com/library/mac/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/00_Introduction.html#//apple_ref/doc/uid/TP40010188
...and the AVFoundation API for Mac:
https://developer.apple.com/library/mac/navigation/index.html?filter=avfoundation#section=Resource%20Types&topic=Reference
Example from Apple on how to record audio (and video):
https://developer.apple.com/library/mac/samplecode/AVRecorder/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011004
if you want to check if a class is available for iOS,macos,tvos or watchOS just go to https://developer.apple.com/documentation/ and search about your class :
For example :
Related
I am following the implementation instructions here to add Sign in with Apple to an existing Xamarin iOS mobile application: https://learn.microsoft.com/en-us/xamarin/ios/platform/ios13/sign-in
If I simply add the following line to AppDelegate.FinishedLaunching():
var appleIdProvider = new ASAuthorizationAppleIdProvider();
I receive the following exception: System.Exception: Could not create an native instance of the type 'AuthenticationServices.ASAuthorizationAppleIdProvider': the native class hasn't been loaded. It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.
I seem to be the only person on the planet that has run into this (and not been able to figure it out themself), as this exact messaging gets zero results on Google. Am I missing a certain reference?
I'm not sure where to even start looking in order to fix this. I downloaded the "official" code sample at https://github.com/xamarin/ios-samples/tree/main/ios13/AddingTheSignInWithAppleFlowToYourApp, and I am unable to find any differences in the project, or in any references.
Thanks in advance!
I figured it out. The simulator I was using was iOS 12.5 - ASAuthorizationAppleIdProvider wasn't introduced until iOS 13.
I have been working with Apple Watch OS 2 for a while, but have not succeeded in triggering vibration on Apple Watch standalone app in Swift, using Xcode Version 7.0 beta 6 (7A192o).
All tutorials using vibration on iPhone in Swift look like:
import AudioToolbox
...
AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
But I cannot import the AudioToolbox library.
I get the error:
Could not build Objective-C module "AudioToolbox"
Has anyone already found the way to do it?
You can generate haptic & auditory feedback, using:
WKInterfaceDevice.currentDevice().playHaptic(.Click)
'Click' is one of the 'cases' (types of vibration/beeps) that you can choose, cfr:
enum WKHapticType : Int {
case Notification
case DirectionUp
case DirectionDown
case Success
case Failure
case Retry
case Start
case Stop
case Click
}
This only works on the device, not in the simulator.
In Swift 3:
WKInterfaceDevice.current().play(.success)
I'm not a expert in WatchKit but I know that with Watch OS 2 you can use:
WKInterfaceDevice().playHaptic(.Notification)
The function playHaptic called on a WKInterfaceDevice instance engage the haptic engine in Apple Watch.
See more in the Apple documentation.
The Correct format is
WKInterfaceDevice.currentDevice().playHaptic(.Notification)
You can easily play the notification sound on watch
Function :
WKInterfaceDevice().playHaptic(.Notification)
Here you have :
Documentation
WKInterfaceDevice.current().play(.failure)
in Swift 3
I'm completely new to Mac development and Swift language. I'm trying to run the Balloons demo from Swift Blog (Here!) in the Playground but in the line:
let scene = SKScene(fileNamed: "GameScene")
I get the error:
Execution was interrupted, reason: SIGABRT
The console shows this:
2014-08-11 22:23:40.647 Balloons[484:303] +[SKScene nodeWithFileNamed:]: unrecognized selector sent to class 0x103d999d8
Since I'm new to Swift I have absolutely no idea whats going on. I've made no modifications in the original code.
Can anyone show me the light here? Thanks.
Be sure to meet requirements that are in the blog post :
This playground uses new features of SpriteKit and requires the latest beta versions of Xcode 6 and OS X Yosemite.
The Balloons playground will not work on OS X Mavericks, even if you use the latest beta version of Xcode.
I'm trying to use the standard Cocoa library in a swift file in Xcode 6 Beta. I followed this instructions but when I import the library
import Cocoa
XCode complains with the error
No such module 'Cocoa'
I also tried with the REPL and I have no problems at all.
I suppose it's a bug, cause I started different projects and only sometimes I get this error. Any suggestions? I'm using Mavericks (10.9.3)
Replace
import Cocoa
With:
import UIKit
You can't import Cocoa from an iOS playground or application. Make sure your code is running in a Cocoa playground (select OS X > Source in the new file dialog).
From your question, it seems that you are trying to add Cocoa class into your iOS Application instead of Cocoa Touch class. So this is not a bug of Xcode.
Be sure to select template which are under the iOS section shown in the following screenshot, as we are choosing it for an iOS Application.
If you've already created your Playground, you can switch between iOS and OS X platforms in the "File Inspector" dialog; there's no need to create a new Playground. import Cocoa will only work for an OS X Playground.
Go to View > Utilities > Show File Inspector and then it's on the right under "Playground Settings"
you need to get xcode 6.1 (beta) to use Swift with OS X
You can open the Utilities tab (from the top right) and just switch platform from the Playground settings section. If you switch it from iOS to OS X the problem will be resolved.
Framework named Cocoa does not exists
Remove
import Cocoa
and everything must works from the scratch.
If this does not work for some reason you can import Foundation or UIKit frameworks
We're developing an OSX app that have to be supported by OSX 10.7 to 10.9. We're currently using QTKit and QTMovieView to show videos, but when trying to upload a new version recently we got this error message:
Deprecated API usage. Apple no longer accepts submissions of apps that use QuickTime APIs.
We have also tested to set the Base SDK to 10.8, but same result there.
And changing to AVKit and AVPlayerView does not work for version prior to 10.9.
So is there a way to use AVKit for versions prior to 10.9 or some way to publish an app with QTKit?
You can't use AVKit on OS X versions prior to Mavericks.
But AVKit is a very small framework that only consists of a player view that has some advanced features out of the box (e.g. chapter navigation, selection & trimming, ... - similar to QTMovieView).
If your app doesn't require those features, you can easily implement a view with simple playback functionality with AVFoundation-only classes (AVFoundation was introduced with OS X 10.7).
Instead of AVPlayerView, you can use a combination of AVPlayer & AVPlayerLayer.
There is some Apple sample code that shows how to build a DIY player view here:
https://developer.apple.com/library/mac/samplecode/AVSimplePlayerOSX/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011060
This custom player view supports:
Play/Pause
Rewind
Playback progress
Fast forward
Volume control