Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS模拟器仅在应用程序从Xcode运行时工作_Ios_Swift_Xcode_Ios Simulator - Fatal编程技术网

iOS模拟器仅在应用程序从Xcode运行时工作

iOS模拟器仅在应用程序从Xcode运行时工作,ios,swift,xcode,ios-simulator,Ios,Swift,Xcode,Ios Simulator,我有一个奇怪的问题在哪里- 在ViewController的viewWillAspect()中,我有一个函数,它执行GET服务调用并将响应存储在全局变量中 响应是一个简单的字符串数组 只有当应用程序从Xcode在模拟器上运行时,这两个步骤才能按预期工作。 当我通常直接在模拟器中启动应用程序时(不是从Xcode启动),服务调用不起作用:-O 我还将此服务调用添加为异步进行。下面是我的代码 override public func viewWillAppear(animated: Bool) {

我有一个奇怪的问题在哪里-

  • 在ViewController的viewWillAspect()中,我有一个函数,它执行GET服务调用并将响应存储在全局变量中
  • 响应是一个简单的字符串数组
  • 只有当应用程序从Xcode在模拟器上运行时,这两个步骤才能按预期工作。

    当我通常直接在模拟器中启动应用程序时(不是从Xcode启动),服务调用不起作用:-O

    我还将此服务调用添加为异步进行。下面是我的代码

    override public func viewWillAppear(animated: Bool) {
            super.viewWillAppear(true)
    
            dispatch_async(dispatch_get_main_queue(), {
                self.fetchCountryTeleCodeList()
            })
    
        }
    
    我可以根据需要提供更多细节

    编辑-1(添加了FetchCountryTelecoodelist代码)

    EDIT-2(添加了FetchCountryTelecoodeList服务调用实现)

    func fetchCountryTelecoodeList(完成:((MyappResult)->Void)){


    这个方法是做什么的?-self.fetchCountryTeleCodeList(),你能发布这个方法的主体吗?请发布这个方法的“self.fetchCountryTeleCodeList()”主体,这样我就可以识别出问题的所在我的问题-添加了代码发生了什么“服务调用不起作用”?@Shallowthough:在模拟器中,当通过xcode运行时,我会得到我的countrycodes响应。但是当独立启动时,此方法从未被调用。我在该方法中放置了一个警报,因为在连接到xcode之前我无法调试。警报从未显示!此方法做什么?-self.fetchCountryTeleCodeList(),您可以发布方法正文吗?请发布此方法“self.fetchCountryTeleCodeList()”正文,以便我可以识别问题的位置我的问题-添加的代码发生了什么“服务调用不起作用”?@Shallowthough:在模拟器中,当通过xcode运行时,我会得到我的countrycodes响应。但是当独立启动时,这个方法从未被调用。我在这个方法中放置了一个警报,因为在连接到xcode之前我无法调试。警报从未显示!
    func fetchCountryTeleCodeList() {
            self.fetchCountryTeleCodeList { result in
                switch result {
                case let .Success(countryCodeString):
                    dispatch_async(dispatch_get_main_queue(), {
                        countryCodes = countryCodeString as! [String]
                        let alert = UIAlertView(title: "MyApp", message: "\(countryCodes)", delegate: self, cancelButtonTitle: "OK")
                        alert.show()
                    })
    
                case .Failure:
                    dispatch_async(dispatch_get_main_queue(), {
    
                        let alert = UIAlertView(title: "MyApp", message: "Internet_Connectivity_Message".localized(), delegate: self, cancelButtonTitle: "OK")
                        alert.show()
    
                    })
                }
            }
        }
    
        ServiceClientArray.requestJSON(ServiceRequest.FetchCountryTeleCodes) { result in
            switch result {
            case let .Success(myArray as NSArray):
                completion(.Success(myArray))
                dispatch_async(dispatch_get_main_queue(), {
    
                    let alert = UIAlertView(title: "MyApp", message: "\(myArray)", delegate: self, cancelButtonTitle: "OK")
                    alert.show()
    
                })
    
            case let .Failure(error):
                dispatch_async(dispatch_get_main_queue(), {
    
                    let alert = UIAlertView(title: "MyApp", message: "\(error)", delegate: self, cancelButtonTitle: "OK")
                    alert.show()
    
                })
    
                completion(.Failure(error))
            default:
                break
    
            }
        }
    }