completionhandler

Swift Firebase Check if user exists

给你一囗甜甜゛ 提交于 2020-01-03 04:39:42
问题 What am i doing wrong? I have a database structure like the one shown in this image. In appleDelegate.swift i just want to check if a certain user token actually exists under the "users" node. that is, if "users" has the child currentUserID (a string token). I understand observeSingleEvent is executed asynchronously.I get this error in swift: 'Application windows are expected to have a root view controller at the end of application launch'. in "func application(_ application: UIApplication" i

Manage completion handler of NSURLSession from a custom class

跟風遠走 提交于 2020-01-03 00:22:07
问题 Part of my app deals with creating a Login check for the user based on a unique code provided to them. To make my application properly structured, I've created a network Helper class to deal with all network operations. Here's How i call my helper class from the controller class (ViewController.m). [[LoginNetworkHelper alloc] loginBasedOnPatientId:@"abc"]; My LoginNetworkHelper class does the following tasks(LoginNetworkhelper.m) - (BOOL)loginBasedOnPatientId:(NSString *)patientId {

Code Not Completing Before Next Method Is Called

烂漫一生 提交于 2019-12-29 09:33:07
问题 In my iOS app, I am using the forecast.io API to get a weather forecast for 3 specific days. Once I get the array from all 3, I want to create an NSMutableArray and add all of those objects to it. The problem I am getting is that it is trying to create the NSMutableArray before the forecast data is retrieved. Here is what I have so far: typedef void(^myCompletion)(BOOL); -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:YES]; [self myMethod:^(BOOL finished) { if(finished){

How do you run code after an async call finishes and the code is outside of the asyn function in swift3

不羁岁月 提交于 2019-12-25 14:48:52
问题 I have an array containing post IDs, then I do a for loop and retrieve each post content and append the post to the post array. After the loop ends, I need to return the post array in the completion handler. However, the .observeSingleEvent is an async method, therefore the posts contents are retrieve from Firebase, the completionhandler(posts) is already executed, which returns an empty array. I want to return the array after every post is appended to the array, similar to making these

Returning method object from inside block

痞子三分冷 提交于 2019-12-25 05:06:47
问题 I am wondering how to do the following correctly: I have a method that is to return an NSData object. It gets the NSData object from a UIDocument . The NSData object can get large, so I want to make sure it is fully loaded before the response starts. I would therefore like to return the value of the method from within the block itself. So something like this: - (NSData*)getMyData { MyUIDocument *doc = [[MyUIDocument alloc] initWithFileURL:fileURL]; [doc openWithCompletionHandler:^(BOOL

Return HTML string from the completion handler of the evaluateJavaScript function

落爺英雄遲暮 提交于 2019-12-24 00:38:44
问题 I know that I'm not the first one to ask this but I can't solve the problem. I'm trying to take a piece of string from HTML using evaluateJavaScript in Xcode with Swift 3 and the piece of text is called value inside the completion handler, so I did like this: var userName = String() func takeData() { webView.evaluateJavaScript("document.querySelectorAll('.name')[0].innerHTML") { (value, error) in if let valueName = value as? String { self.userName = valueName } print(value) print(error) } }

Completion handler in For/In loop - swift

守給你的承諾、 提交于 2019-12-22 12:43:30
问题 How can you implement a completion handler in a For/In loop ? I have an array of two CNLabeledContact called phonesArray : var myPhoneNumberArray = CNLabeledValue for item in phonesArray { let phonesArrayValue = item.value as! CNPhoneNumber let phonesArrayValueDigits = phonesArrayValue.valueForKey("digits")! print("current value: \(phonesArrayValueDigits)") // DataService.dataService.checkIfPhoneExistsInDatabase("\(phonesArrayValueDigits)") { (bool) in if bool { print("append this item") self

How can I make a function complete before calling others in an IBAction?

半世苍凉 提交于 2019-12-22 09:48:01
问题 I'm having trouble understanding completion handlers. I have a textFieldEditingDidChange IBAction that calls first a verify() function on the textfield input and then an if statement on the boolean returned by apply. The problem is that the if statement starts before verify() has finished . Here is the code: @IBOutlet weak var myTextField: UITextField! @IBAction func myTextFieldEditingDidChange(sender: AnyObject) { let yo = verify(myTextField.text!) print("\(yo)") // it always prints "true"

Resuming tasks using NSURLSession when app removed from background or on device reboot

为君一笑 提交于 2019-12-22 05:11:14
问题 I have checked many docs but could not found solution for Resuming tasks using NSURLSession when app removed from background or on device reboot. I am dealing with amazon S3 to upload some files, In that I am able to Upload file to S3 using NSURLSessionUploadTask, when app is in foreground as well as in background. Resume task when app crashed due to any other reason while uploading and if app is not removed from background. Restart task if I reboot device while uploading and if app is not

Completion handler is not called on iOS7 GM

北慕城南 提交于 2019-12-18 12:14:32
问题 I'm using AVAssetWriter, and it is perfectly working on iOS6. The problem is, when I called finishWritingWithCompletionHandler , the completion handler is not called on iOS7 GM. I called markAsFinished , and even endSessionAtSourceTime before I call finishWritingWithCompletionHandler. It works fine on iOS6. And even more, on iOS7, it works some times, and then it doesn't work again. I don't know why, but it works if I call the method using alert view. So I tried performSelectorOnMainThread