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
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 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 :
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
I try to get the UDID without using the UIDevice class but directly from implementing the dynamic library liblockdown.dylib on iOs 4.2. I don't find any documentation. All I need is to get the kLockdownUniqueDeviceIDKey, what should I do ?
I don't know about iOS 4, but I know that the UDID can also be retrieved on iOS 5, 6 and 7 using the libMobileGestalt.dylib. More information about this library can be found on the iPhone Development Wiki.
Here is the header for the liblockdown.dylib
here implementation:
https://github.com/theiostream/lockdown-uiduid/blob/master/main.mm
This code work on iOS 6.1.3 but it does not work on iOS 7b2 :(