Hello! I've been having a problem wherein my app runs on the iOS simulator but won't build to the generic device. When I check the report navigator it always shows the same arrow next to the same file. (FirstViewController.swift)
Here's the XCode report navigator (it's been like this for about half an hour)
If anyone has had the same problem or knows a way to fix this, you'd be a complete livesaver!
Also, here is my Podfile (the problem doesn't seem to be coming from Cocoapods though - and I do use the .xcworkspace file)
# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
use_frameworks!
target 'Channel 2' do
pod 'PopupDialog', '~> 0.3'
pod 'Socket.IO-Client-Swift', '~> 6.1.6' # Or latest version
pod 'YouTubePlayer'
pod 'SwiftyJSON'
end
target 'Channel 2Tests' do
pod 'PopupDialog', '~> 0.3'
pod 'Socket.IO-Client-Swift', '~> 6.1.6' # Or latest version
pod 'YouTubePlayer'
pod 'SwiftyJSON'
end
target 'Channel 2UITests' do
pod 'PopupDialog', '~> 0.3'
pod 'Socket.IO-Client-Swift', '~> 6.1.6' # Or latest version
pod 'YouTubePlayer'
pod 'SwiftyJSON'
endAnd finally here is FirstViewController.swift. Occasionally it would give me an error that the class Poll could not be found (it was in another file that was added to the project) so I moved it inside FirstViewController.swift
/
/
/
/
/
/
/
import UIKit
import PopupDialog
import SocketIOClientSwift
class FirstViewController: UIViewController {
/
var poll:Poll!
/
let socket = SocketIOClient(socketURL: NSURL(string: "http:/
/
@IBOutlet var logo: UIImageView!
@IBOutlet var top: UILabel!
@IBOutlet var bottom: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
/
top.text = "Channel 2"
bottom.text = "Connecting to server..."
/
self.socketHandlers();
self.socket.connect();
}
/
func socketHandlers() {
self.socket.on("poll") {[weak self] data, ack in
self!.poll = Poll(_choices: [data[0][0] as! String, data[0][1] as! String, data[0][2] as! String, data[0][3] as! String], _correct: data[1].integerValue, _prompt: (data[2] as? String)!);
self!.displayPollPopup()
}
self.socket.on("live") {[weak self] data, ack in
self!.logo.image = UIImage(named: "green_logo");
self!.top.text = "Channel 2: ON AIR!"
self!.bottom.text = "Thanks for watching!"
}
self.socket.on("results") {[weak self] data, ack in
self!.popupmessage("The vote ended!", msg: data[0] as! String);
}
self.socket.on("videos") {[weak self] data, ack in
NSUserDefaults.standardUserDefaults().setObject((data[0] as! String), forKey: "videos");
print(data[0] as! String)
}
}
/
func displayPollPopup() {
var popupTitle = "poll!";
if(poll.hasCorrectAnswers())
{
popupTitle = "question!"
}
let popup = PopupDialog(title: "Answer this " + popupTitle, message: poll.getprompt());
let buttonOne = DefaultButton(title: poll.getchoices()[0], action: { self.vote(0) });
let buttonTwo = DefaultButton(title: poll.getchoices()[1], action: { self.vote(1) });
let buttonThree = DefaultButton(title: poll.getchoices()[2], action: { self.vote(2) });
let buttonFour = DefaultButton(title: poll.getchoices()[3], action: { self.vote(3) });
popup.addButtons([buttonOne, buttonTwo, buttonThree, buttonFour]);
self.presentViewController(popup, animated: true, completion: {});
}
func popupmessage (t: String, msg:String) {
let popup = PopupDialog(title: t, message: msg);
let button = DefaultButton(title: "Okay", action: nil)
popup.addButton(button);
self.presentViewController(popup, animated: true, completion: nil)
}
func vote(choice:Int) {
self.socket.emit("vote", poll.getchoices()[choice]);
}
/
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
/
}
}
class Poll: NSObject {
private var choices:[String]!;
private var correct:Int!
private var prompt = "";
init(_choices:[String], _correct:Int, _prompt:String)
{
self.choices = _choices;
self.correct = _correct;
self.prompt = _prompt;
}
internal func hasCorrectAnswers() -> Bool
{
if(self.correct != -1) { return true }
return false;
}
internal func isCorrect(selection: String) -> Bool
{
if(self.choices[correct] == selection) { return true }
return false;
}
internal func getchoices() -> [String] {
return self.choices;
}
internal func getprompt() -> String {
return self.prompt;
}
}Sidenote: The app conects to a Socket.IO node.js server, but in the simulator it works fine regardless of the server's reachability.
I'm sorry this post was so long, if anyone knows a way to fix this that'd be such a relief, I have no idea why it doesn't work.
Thanks!
- Brendan