swift2

SKAudioNode() crashes when plugging in/out headphones

安稳与你 提交于 2020-01-01 08:34:06
问题 I am using a SKAudioNode() to play background music in my game. I have a play/pause function and everything is working fine until I plug in my headphones. There is no sound at all and when I call the pause/play function I get this error AVAudioPlayerNode.mm:333: Start: required condition is false: _engine->IsRunning() com.apple.coreaudio.avfaudio', reason: 'required condition is false: _engine->IsRunning() Does anyone knows what this means? Code: import SpriteKit class GameScene: SKScene {

New Firebase Facebook login

旧城冷巷雨未停 提交于 2020-01-01 05:14:32
问题 I'm trying to make a Facebook login with the new Firebase platform. this is the code for the facebook login let facebookLogin = FBSDKLoginManager() facebookLogin.logInWithReadPermissions(["email"], fromViewController: self) { (result, error) -> Void in if error != nil { print("error is \(error)") } else { let accessToken = FBSDKAccessToken.currentAccessToken().tokenString let credential = FIRFacebookAuthProvider.credentialWithAccessToken(accessToken) AUTH?.signInWithCredential(credential,

How to activate “Installed” programmatically?

旧时模样 提交于 2020-01-01 04:24:28
问题 This is an UIView and I want to activate it (with its constraints etc.), when I want, how to do that? I don't want removefromsuperview etc. Just want to learn this Installed function exact equivalent in terms of code. 回答1: There are two options 1) hide 2) removeFromSuperview . If You install or uninstall view from storyboard , It is equivalent to add/remove view. refer this apple documentation it says, A runtime object for an uninstalled view is still created. However, the view and any

How to change the NSTimeInterval of an NSTimer after X seconds?

核能气质少年 提交于 2019-12-31 05:10:19
问题 I'm making an app in swift 2 where there is two timers. After 10 seconds I would like another timer to go faster. I have tried doing it like this but it didn't work (I'm trying to change the var time to 1): @IBOutlet var displayTimeLabel: UILabel! var startTimer = NSTimeInterval() var timer = NSTimer() var timer2:NSTimer = NSTimer() var time = 2.0 @IBAction func Start(sender: UIButton) { if !timer2.valid { timer2 = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector:

Swift iOS 9 NSURLErrorDomain Error -1004

血红的双手。 提交于 2019-12-31 03:23:30
问题 I'm using Swift 2 and Alamofire with both iOS 9 and iOS 8. In iOS 8 all my requests to my API work fine. In iOS 9 they immediately fail with a -1004 NSURLErrorDomain with the message "Could not connect to the server.". I read about Apple's change with App Transport Security and already added the entry to my Plist to disable it and allow insecure connections. I'm at a loss as to the reason for this error...any help would be great! 回答1: After messing around with a ton of different keys and

How to catch error when setting launchpath in NSTask

那年仲夏 提交于 2019-12-30 18:01:11
问题 I am trying to run a commandline tool using swift 2 on a mac (10.10): let task = NSTask() task.launchPath = "/path/to/wrong/binary" task.launch() // NSPipe() stuff to catch output task.waitUntilExit() // never reached if (task.terminationStatus != 0){ NSLog("uh oh") } Since the path is wrong, my program dies with launch path not accessible . However, I don't know, how to catch this error. Using do { try } catch {} around task.launch() does not work, because it does not throw an exception,

Why can't I pass an optional Swift String to C function that allows NULL pointers?

两盒软妹~` 提交于 2019-12-30 11:42:10
问题 I have a C function that deals with C strings. The function actually allows strings to be NULL pointers. The declaration is like follows: size_t embeddedSize ( const char *_Nullable string ); It is no problem to use this function like this in C: size_t s1 = embeddedSize("Test"); size_t s2 = embeddedSize(NULL); // s2 will be 0 Now I'm trying to use it from Swift. The following code works let s1 = embeddedSize("Test") let s2 = embeddedSize(nil) // s2 will be 0 But what doesn't work is passing

Swift Send Email with MailGun

耗尽温柔 提交于 2019-12-30 11:00:13
问题 Problem I would like to use the MailGun service to send emails from a pure Swift app. Research So Far As I understand it, there are two methods to send an email via MailGun. One is to email MailGun with the emails, and MailGun will redirect it (See Send via SMTP ). That will, as I understand it, not work, as iOS cannot programatically automatically send mail, and must use methods that require user intervention. As such, I should use the API directly. As I understand it, I need to open a URL

Issue with Swift 2 Error Handling

别等时光非礼了梦想. 提交于 2019-12-30 10:05:09
问题 I am using REST to get JSON data and then parse it. To do this I am using NSJSONObjectWithData, as far as I'm aware this method used to have an error handler within its parameters but it's no longer there. In my code here: let err: NSError? let options:NSJSONReadingOptions = NSJSONReadingOptions.MutableContainers var jsonResult = NSJSONSerialization.JSONObjectWithData(data!, options: options) as! NSDictionary; I get an error which says: "Call can throw, but it is not marked with 'try' and the

Issue with Swift 2 Error Handling

爷,独闯天下 提交于 2019-12-30 10:04:27
问题 I am using REST to get JSON data and then parse it. To do this I am using NSJSONObjectWithData, as far as I'm aware this method used to have an error handler within its parameters but it's no longer there. In my code here: let err: NSError? let options:NSJSONReadingOptions = NSJSONReadingOptions.MutableContainers var jsonResult = NSJSONSerialization.JSONObjectWithData(data!, options: options) as! NSDictionary; I get an error which says: "Call can throw, but it is not marked with 'try' and the