logo
down
shadow

No response when calling NSURLConnection in mixed Swift Objective-C environment


No response when calling NSURLConnection in mixed Swift Objective-C environment

By : Proximity86
Date : November 21 2020, 01:01 AM
This might help you The while !parseCompleted loop is blocking the main thread until the download and parsing is done. But the processing of the received data happens on the main thread, too, so if that thread is blocked, your app will be deadlocked.
I would eliminate that while loop and put all of the post processing inside your receivedDataComplete method.
code :
class CheckActuality: NSObject, GetReceivedDataProtocol, WordPressParserDelegate {

    let errorDomain = "com.domain.app.CheckActuality"

    lazy var retrievePostData = StartConnection()
    lazy var wpParser = WordPressParser()
    lazy var defaults = NSUserDefaults.standardUserDefaults()

    var completionHandler: ((latestPost: Bool!, error: NSError?)->())!

    func isActual(completionHandler: (latestPost: Bool!, error: NSError?)->()) {
        // save the completionHandler, which will be called by `receiveDataCompleted` or `wpParseCompleted`

        self.completionHandler = completionHandler

        // now perform query

        let url = "http://blablablog.nl/new_api.php?function=get_recent_posts&count=1"  // as an aside, use `let` here
        retrievePostData.delegate = self                                                // also note that use of `self` is redundant here
        retrievePostData.getRssFileWithUrl(url, forBlog:true)
    }    

    func receiveDataCompleted () {
        if retrievePostData.receivedDataComplete != nil {
            wpParser.delegate = self
            wpParser.parseData(retrievePostData.receivedDataComplete)
        } else {
            // frankly, I'd rather see you change this `receiveDataCompleted` return the `NSError` from the connection, but in the absence of that, let's send our own error
            let error = NSError(domain: errorDomain, code: 1, userInfo: nil)
            completionHandler(latestPost: nil, error: error)
        }
    }

    func wpParseCompleted () {
        if wpParser.arrayWithPostDictionaries.count == 1 {                     // Some info has been retrieved
            let posts: NSArray = wpParser.arrayWithPostDictionaries
            let post: NSDictionary = posts.objectAtIndex(0) as NSDictionary
            let latestPost: String = post.objectForKey("postUrl") as String
            let currentlatestPost = defaults.stringForKey("ttt")

            completionHandler(latestPost: (latestPost != currentlatestPost), error: nil)
        }

        // again, I'd rather see you return a meaningful error returned by the WordPressParser, but I'll make up an error object for now
        let error = NSError(domain: errorDomain, code: 2, userInfo: nil)
        completionHandler(latestPost: nil, error: error)
    }

}
let checkActuality = CheckActuality()

func someFunc() {
    checkActuality.isActual() { latestPost, error in 
        if error != nil {
            // do whatever error handling you want

            println(error) 
        } else if latestPost {
            // yes, latest post
        } else {
            // nope
        }
    }

    // note, do not try to check `latestPost` here because the 
    // above closure runs asynchronously
}


Share : facebook icon twitter icon
Objective-C: NSURLConnection response?

Objective-C: NSURLConnection response?


By : Nick Qiu
Date : March 29 2020, 07:55 AM
I hope this helps you . The response format is in NSData, and someone can correct me if I am wrong, but that's what gets shown if printed with NSLog. You can convert it to an NSString like this and see if it helps:
code :
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
Objective-C: NSURLConnection, when to starting working with the response?

Objective-C: NSURLConnection, when to starting working with the response?


By : user3024068
Date : March 29 2020, 07:55 AM
hop of those help? connectionDidFinishLoading is the correct place to start working with the received data.
didReceiveData is the correct place to append the newly received data (not didReceiveResponse).
Objective C NSURLConnection dosen't get response data

Objective C NSURLConnection dosen't get response data


By : kumar
Date : March 29 2020, 07:55 AM
this one helps. didReceiveData may be called N (several) times. save the data to a mutably data buffer (queue it up) and in didFinish read it into a string
mock code:
code :
- (void) getVitsTitelByID:(int)identifier {
    NSString *url = [NSString stringWithFormat:@"http://webserver.com/ivitserdk.php?function=gettitelbyid&id=%d", identifier];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:1.0];
    connectionTitelByID = [[NSURLConnection alloc] initWithRequest:request delegate:self];

    dataForConnectionTitelByID = [NSMutableData data];
    [connectionTitelByID start];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    if(!data.length) return;

    if(connection == connectionTitelByID)
        [dataForConnectionTitelByID appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    if(connection == connectionTitelByID) {
        id str = [[NSString alloc] initWithData:dataForConnectionTitelByID encoding:NSUTF8StringEncoding];
        NSLog(@"%@",str);
        dataForConnectionTitelByID = nil;
        connectionTitelByID = nil;
    }
}
Objective-c and Swift mixed project -Swift.h file report errors

Objective-c and Swift mixed project -Swift.h file report errors


By : Aum Fiinz
Date : March 29 2020, 07:55 AM
wish of those help I find out the error why appear:
My project in the SVN, deleted the AppDelegate.h and AppDelegate.m and main.m, and replaced with AppDelegate.swift, means replace Objective-C's AppDelegate to Swift's AppDelegate, but in my this macbook, the Objective-C's AppDelegate is still keep.
Swift classes marked with @objc not being added to "-Swift.h" header in mixed Objective-C/Swift framework

Swift classes marked with @objc not being added to "-Swift.h" header in mixed Objective-C/Swift framework


By : Himansu Sekhar Bishi
Date : March 29 2020, 07:55 AM
I wish this helpful for you I had a similar issue. In my case it was a known issue in Xcode 10.2:
https://developer.apple.com/documentation/xcode_release_notes/xcode_10_2_release_notes
Related Posts Related Posts :
  • FBSessionStateClosedLoginFailed when I am logged in through Settings
  • CGRect positioning according to center point
  • iOS: Update table view datasource with animations without core data
  • iOS : Where to start for AliPay integration?
  • Routing App Coverage File missing but not needed?
  • Drawing on a zoomable view
  • Append NSStrings and NSNumber to NSMutableArrays and make NSMutable dictionary
  • Terminating app due to uncaught exception 'NSRangeException' when calling dequeueReusableCellWithReuseIdentifier:forInde
  • Collision without physics (Cocos2D + Box2D iOS)
  • Creating a percentage based iOS layout
  • Update tableView row from AppDelegate Swift 4
  • Assigning return value of a class method to a variable error
  • how to display circular progress in delphi ios apps?
  • I can't figure how to fix this Expected identifier or '('
  • How to Test APIs in Swift 4?
  • Link error /Build/Products/Debug-iphonesimulator file not found
  • working with a very large JSON object in iOS
  • Turn off part of the iPhone Screen
  • Phonegap 3.0 app with facebook login using xCode
  • How to add interstitial admob ads to my ios project
  • adding tapku calendar to ios app
  • Add an alertcontroller in a global swift file?
  • Take square image with Cordova (Phonegap) Camera API?
  • Amazon S3 policy allowing only upload not overwrite
  • How to change the UILabel content by tapping?
  • Adding checkmark to selected table cell also checks another table cell
  • UICollectionView cellForItemAtIndexPath indexPath row is nil
  • Resize and set quality on JPEG image while retaining EXIF in iOS
  • How to push rootviewcontroller in Ios
  • How to add UIBarbuttonItem at centre on UInavigationbar in iOS
  • Would this IOS device test crash be expected
  • PickerView not showing any values
  • How to set root view controller in storyboard animated with navigation controller programmatically
  • Can anyone suggest me the effective way to deal with s3 upload fail because of timezone difference issue?
  • Getting list of files in documents folder
  • Error while using Realm Object as a singleton. Is it a good idea?
  • inserting into SQLite database
  • More nodes than I should
  • Facebook IOS SDK navigate to another controller after login not working
  • Swift Array - use "Contains" of type AnyObject
  • Sidebar menu with indicate navigationbar on iOS
  • Programmatically set size of UIView from Storyboard
  • Navigation bar blink
  • Web services issue on POST method
  • Parse.com error 'Method not allowed when Pinning is enabled.' when I use a PFQueryTableViewController subclass
  • Swift can't send URLRequest at all?
  • No Provisiong profiles with a valid signing identity were found and Failed to locate or generate matching signing assets
  • iOS: how to set httponly flag for NSHTTPCookie
  • How to get the mac address of a beacon in objective-c without knowing its UUID, major and minor values?
  • tableView is not showing data from JSON in swift
  • iTunes reject app for date of birth
  • SWIFT reporting "Extra argument in call" - works in Playground
  • save data depending on passed value in swift
  • webview not showing on full Screen of iphone 6
  • Location Notification's based on Latest iOS Feature
  • Adjusting Height of UITableViewCell
  • How to show five digit unicode in iphone
  • unwind doesn't work
  • Confusion about coordinates, frames & child nodes in SpriteKit on iOS?
  • If Statements not being recognized by Xcode
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org