completionhandler

losing data while writing through asynchronousFileChannel in java

老子叫甜甜 提交于 2019-12-03 21:25:10
I am trying to use asynchronousFileChannel to write the date into a text file. I made 3 jar file of the program with the AsynchronousFileChannel and compiled all 3 jars simultaneously through command prompt to read 3 different text files and output to one common temporary file I have 2000 records in my test files(3) to be read,but the output in the common temporary file is missing some of the records,the output should have 6000 records but it shows only 5366 or 5666 or sometimes less than that. I am not able to figure out why some data is lost as it is the functionality of a

Wait for completion handler to finish - Swift

馋奶兔 提交于 2019-12-03 15:25:15
I am trying to check if UserNotifications are enabled and if not I want to throw an alert. So I have a function checkAvailability which checks multiple things, including the UserNotification authorization status. func checkAvailabilty() -> Bool { // // other checking // var isNotificationsEnabled = false UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound], completionHandler: { (granted, error) in if granted { isNotificationsEnabled = true } else { isNotificationsEnabled = false } }) } if isNotificationsEnabled { return true } else { // Throw alert: Remind user to

Getting data out of completionHandler in Swift in NSURLConnection

时间秒杀一切 提交于 2019-12-03 04:32:36
问题 I am trying to write a function that will execute an asynchronous GET request, and return the response (as any data type, but here it is as NSData). This question is based on: How to use NSURLConnection completionHandler with swift func getAsynchData() -> NSData { var dataOutput : NSData let url:NSURL = NSURL(string:"some url") let request:NSURLRequest = NSURLRequest(URL:url) let queue:NSOperationQueue = NSOperationQueue() NSURLConnection.sendAsynchronousRequest(request, queue: queue,

Swift || Returning a class that can be used by other methods from an API call

旧巷老猫 提交于 2019-12-02 19:01:34
问题 I am making a call to HERE Weather API from a mobile App and need to return the current weather as an object so that other methods can use that information for a given time period (eg. 30 min update intervals). I have a rough understanding of asynchronous calls based on this site https://fluffy.es/return-value-from-a-closure/ but I am still running into my problem where I can't access the Weather object I create outside of the closure of the completionHandler. I have provided the Get method

Getting data out of completionHandler in Swift in NSURLConnection

夙愿已清 提交于 2019-12-02 17:42:20
I am trying to write a function that will execute an asynchronous GET request, and return the response (as any data type, but here it is as NSData). This question is based on: How to use NSURLConnection completionHandler with swift func getAsynchData() -> NSData { var dataOutput : NSData let url:NSURL = NSURL(string:"some url") let request:NSURLRequest = NSURLRequest(URL:url) let queue:NSOperationQueue = NSOperationQueue() NSURLConnection.sendAsynchronousRequest(request, queue: queue, completionHandler:{ (response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in /* this next line

Objective C How to return outer function from inside async inner function

孤街浪徒 提交于 2019-12-02 15:23:54
问题 I want to return from outer function from inside async inner function. In swift, I would have used completion handler for this purpose which would escape from function. But in objective c, completion handler won't actually return from function: My function looks like this: -(void)chosenFrom:(NSDictionary<NSString *,id> *)info{ [self asyncCode:info withCompletion:^(NSData *imageData) { if(imageData) { // I want to return from chosenFrom function ***inside here.*** } }]; // This is to

Swift || Returning a class that can be used by other methods from an API call

半腔热情 提交于 2019-12-02 12:22:41
I am making a call to HERE Weather API from a mobile App and need to return the current weather as an object so that other methods can use that information for a given time period (eg. 30 min update intervals). I have a rough understanding of asynchronous calls based on this site https://fluffy.es/return-value-from-a-closure/ but I am still running into my problem where I can't access the Weather object I create outside of the closure of the completionHandler. I have provided the Get method from my Weather class. I have also provided a call to that Get method in the AppDelegates file. public

How To Call a func within a Closure

狂风中的少年 提交于 2019-12-02 09:58:43
In a model's class Location , I get the name of the current city: var currentLatitude: Double! var currentLongitude: Double! var currentLocation: String! var currentCity: String! func getLocationName() { let geoCoder = CLGeocoder() let location = CLLocation(latitude: currentLatitude, longitude: currentLongitude) geoCoder.reverseGeocodeLocation(location, completionHandler: { placemarks, error in guard let addressDict = placemarks?[0].addressDictionary else { return } if let city = addressDict["City"] as? String { self.currentCity = city print(city) } if let zip = addressDict["ZIP"] as? String {

What's the most efficient way to refresh a tableView every time the app is pushed back to the foreground?

杀马特。学长 韩版系。学妹 提交于 2019-12-02 07:55:12
Currently what I have is this: AppDelegate.applicationDidBecomeActive(): func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. guard let vc = self.window?.rootViewController?.children.first as! AlarmTableViewController? else { fatalError("Could not downcast rootViewController to type AlarmTableViewController, exiting") } vc.deleteOldAlarms(completionHandler: { () -> Void in vc.tableView.reloadData()

UIActivityViewController completion handler still calls action if user presses cancel

谁都会走 提交于 2019-12-01 15:51:33
问题 In my UIActivityViewController, I use completion handler to execute a "successfully shared" notification. It works but my only problem is, it still shows the notification if the user presses cancel. Here is my completion handler code, [controller setCompletionHandler:^(NSString *activityType, BOOL completed) { CWStatusBarNotification *notification = [CWStatusBarNotification new]; [notification displayNotificationWithMessage:@"✓ Successfully Shared Centre!" forDuration:3.0f]; notification