I have been working on an application involving client-server communication. Everything was working fine until iOS 7.1. Now that Xcode 6 GM Seed in launched, I tried to build and run the project on iOS8 simulator. However, all NSURLConnections seem to time out now. I can not get any response from the server. This works on iOS 7 simulator and Xcode 6.
I tried using the NSURLSession hoping that would resolve the issue. But it hasnt.
Any help will be highly appreciated!! If anyone else has faced this issue, please let me know if you have any workaround to this.
UPDATE:
This is the code I have used:
NSString *authStr = [NSString stringWithFormat:#"%#:%#", username, password];
NSData *authData = [authStr dataUsingEncoding:NSUTF8StringEncoding];
NSString *authValue = [NSString stringWithFormat: #"Basic %#",[authData base64EncodedStringWithOptions:0]];
[inURLRequest setValue:authValue forHTTPHeaderField:#"Authorization"];
Please note that the inURLRequest is already iniatlized with the desired URL.
After this just use the inURLRequest to fire the transaction as usual. For eg., in case of NSURLSession, create a download task using this request object and call resume API on it.
Well, I have found a fix for this issue.
The app had basic authentication in place for each REST webservice. This means that we used to get an authentication challenge for each webservice where we sent the credentials back with the challenge.
I changed this to send the credentials in the request header (in encrypted format) as a header field.
I am not sure how this was working in iOS 7 and not in iOS 8. But this seems to have fixed my problem :).
If you are streaming data to the NSURLConnection make sure you write new data exactly once when the stream event hasSpaceAvail has arrived - I found I had connection issues when I had wrong handling of the hasSpaceAvail event.
do not write more than once in response to the event
do not write zero times (or else you won't get another hasSpaceAvail event)
Related
Alright, I am having a devil of a time with getting some basic user info from the Facebook IOS SDK (3.1.1). Having done FB development with other platforms I am pretty convinced my issue has to do with the FB app's set up than with my code. BTW, I am in iTunes and have set an iTunes ID for iPhone. I have also carefully checked and quadruple checked the bundle ID in the App set up against my bundle ID.
Right now I can authenticate with a test user and get all the detail, etc. It works great. When I log in as a real user like myself (and I am a developer on the project) I get an Auth token, but calls to get the user fail, and I'm not sure what I have done wrong (if it works for a test user it should work for everyone).
All I need to get from the user, BTW is their First name, Last name, FB User ID, and email address (optional, but requested).
Currently after authenticating using the I'm using the games tutorial. Once I am logged in I do the following (although I have done a bunch of other things with the same result):
- (void)fbDidLogin
{
// removed the setup for the class level Facebook var that I am currently not using
// get information about the currently logged in user
NSString *fql = #"select uid, first_name, last_name, email from user where uid = me()";
NSDictionary *queryParam = [NSDictionary dictionaryWithObjectsAndKeys:fql, #"q", nil];
[FBRequestConnection startWithGraphPath:#"/fql"
parameters:queryParam
HTTPMethod: #"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
[self meRequestResult:result WithError:error];
}];
}
The meRequestResult routine starts like this:
- (void)meRequestResult:(id)result WithError:(NSError *)error
{
if ([result isKindOfClass:[NSDictionary class]])
{
NSDictionary *dictionary;
if([result objectForKey:#"data"])
dictionary = (NSDictionary *)[(NSArray *)[result objectForKey:#"data"] objectAtIndex:0];
else
dictionary = (NSDictionary *)result;
[fbUserData release];
fbUserData = [dictionary retain];
NSString *facebookId = [dictionary objectForKey:#"id"];
if(!facebookId)
facebookId = [dictionary objectForKey:#"uid"];
// and more follows that is not pertinent
When I turn on request logging in the FB IOS SDK. I see the same things and can not find any description anywhere what these mean.
Here's the last 10 or so lines from the log:
2012-12-03 11:52:12.394 mTender[6572:1cd03] Reachability Flag Status: -R -----l- networkStatusForFlags
2012-12-03 11:52:12.395 mTender[6572:1cd03] The internet is working via WIFI.
2012-12-03 11:52:12.396 mTender[6572:1cd03] Reachability Flag Status: -R ------- networkStatusForFlags
2012-12-03 11:52:12.396 mTender[6572:1cd03] A gateway to the host server is working via WIFI.
2012-12-03 11:52:35.093 mTender[6572:1cd03] FBSDKLog: Request <#1111>:
URL: https://graph.facebook.com//fql?sdk=ios&access_token=ACCESS_TOKEN_REMOVED&q=select%20uid%2C%20first_name%2C%20last_name%2C%20email%20%20from%20user%20where%20uid%20%3D%20me%28%29&migration_bundle=fbsdk%3A20121003&format=json
Method: GET
UserAgent: FBiOSSDK.3.1.1
MIME: multipart/form-data; boundary=3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f
2012-12-03 11:52:37.194 mTender[6572:1cd03] Error: HTTP status code: 500
2012-12-03 11:52:37.196 mTender[6572:1cd03] FBSDKLog: Response <#1111> <Error>:
The operation couldn’t be completed. (com.facebook.sdk error 5.)
Hopefully someone can figure this out. It's the last step of this project..
I am doing something very similar to you. I am using facebook for login so that I don't have to worry about storing passwords and what not.
I followed this set of instructions.. The facebook site seems to be horrid the way its layed out with out of date stuff all over the place.
You can use native facebook or web based user authentication (the SDK will manage all that) so it will work on older versions of iOS and when not signed in to native facebook.
You will set a handler which will give you a "NSDictionary *user" with all the stuff that you need. No need to use the graph api on the iphone client.
i think you have to see alternate way because the REST API has been deprecated. To make FQL queries you have to use the Graph API call.
http://developers.facebook.com/docs/reference/rest/fql.query/
OK, I'm going to close this out.
I reverted to an SDK back in November of 2011. It didn't seem to be working at first, and then it just started working. I suspect a bug on Facebook's end was causing this. I haven't updated to the latest again to try, but this is my only guess as to what happened.
If you've done any lengthy Facebook development you know that sometimes their bugs really make things difficult. That said, no idea if this is the actual answer since I really didn't make any coding changes from the original code.
I know that I purposefully left the bundle ID out of the FB App Setup..
My App connects to a server and based on a cookie the server will issue a different response.
Is it no possible to programmatically clear the cookie store, so that the server will not recognize my App when it contacts the server the next time.
I gathered that clearing the Cookies in the Settings.app does only apply for cookies within Safari.
Thanks very much for your comment.
Okay... following up on my earlier comment (and hoping this is the solution you are looking for), you probably want to utilize:
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:]
for each of the cookies for your site.
If you want your changes to the NSHTTPCookieStorage to be retained, you'll also want to call off to
[[NSUserDefaults standardUserDefaults] synchronize];
To prevent this from slowing down your app, you may also want to call this on a background thread like so:
dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
dispatch_async(backgroundQueue, ^{
//TODO: Cookie deletion logic here
});
EDIT:
If you just need to disregard cookies altogether for a given NSURLRequest, you can do so with:
[request setHTTPShouldHandleCookies:NO];
Where request is your instance of NSURLRequest.
As mentioned by #Niralp it isn't possible to delete all cookies by passing nil to deleteCookie: on an instance of NSHTTPStorage. However, since iOS 8 there has been a removeFromDate: method that can be utilised to the same effect.
In Swift 4 this would be:
HTTPCookieStorage.shared.removeCookies(since: Date(timeIntervalSince1970: 0))
That would remove all cookies in the app since the 1970 epoch which is likely suitable for most needs.
I have wifi connected in the devices - so this is ruled out.
The Application i have with the same following code executed is able to upload the file to a java server in the iOS 4.3 simulator but unable to upload in iOS 4.3.3 device. This is kind of strange.
ASIFormDataRequest *request_zip = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:strURL]];
[request_zip setAllowCompressedResponse:YES];
[request_zip setPostValue:#"device" forKey:#"value1"]; //pass device ID here...
//[request_zip addRequestHeader:#"Content-Type" value:#"multipart/form-data"];
[request_zip setTimeOutSeconds:20];
[request_zip setDelegate:self];
[request_zip setDidFailSelector:#selector(uploadFailed:)];
[request_zip setDidFinishSelector:#selector(uploadFinished:)];
[request_zip setFile:path forKey:path];
[request_zip startAsynchronous];
NSLog(#"%# post length",[NSString stringWithFormat:#"%llu",[request_zip postLength]]);
The code when executed results the following output in the terminal.
Incorrect NSStringEncoding value 0x0000 detected. Assuming NSStringEncodingASCII. Will stop this compatiblity mapping behavior in the near future.
The post length printed in the console =>
0 post length
There is also a another string comes up lastly, i.e the time out message,
Request failed:
The request timed out with response data
100% sure that the server is active and responds immediately for the app executed from simulator.
how is it possible to have a program running in simulator properly but not in the device?
Incorrect NSStringEncoding value
0x0000 detected. Assuming
NSStringEncodingASCII. Will stop this
compatiblity mapping behavior in the
near future.
Means that you have a NSString that is being initalized without a NSStringEncoding value, check your NSString calls.
Empty body in POST in ASIHTTPRequest
Try:
NSURL *requestURL = [NSURL URLWithString:[NSString stringWithFormat:#"%#", strURL]];
ASIFormDataRequest *request_zip = [ASIFormDataRequest requestWithURL:requestURL];
The NSLog will fire right after the [request_zip startAsynchronous]; which at that time may just be initialized, you need to move the log request into a delegate method, change this to [request_zip startSynchronous]; and it will fire immediately,.
Then your delegate method will look like this:
- (void)requestStarted:(ASIHTTPRequest *)request {
NSLog(#"%# post length",[NSString stringWithFormat:#"%llu",[request postLength]]);
}
The problem was with the server end. ASIHTTP lib works properly, when ASI tries to transmit the request with post body to server, the apache didnt respond back properly as one of the server configuration was missing probably. The proprietary web library owners fixed it later and the problem is resolved.
It worked in simulator but not in device, why?
It worked in simulator coz the data is transmitted thru the ethernet not wireless, so the transmission rates were great comparatively.
Web service developers has to plz make sure that the data is received even
if it comes in from low speed networks
**
ASI libs returned ASCII encoding error, why?
**
This error is returned by ASI immediately once the request goes time - out. This is the cause, but the real internal problem with ASI for this error has to be found out.
Very interesting results fetched end of the day.
Hi I'm trying to build a simple chat client between two ipod touches Just as a start to learning Bonjour.
I connect the two devices fine and everything seems like it should work. I can send the data with no problems (no error) , but When I should then receive the data and I dont. When I look in the log, I see "GCKSessionEvent_IncomingOOBPacket: failed to create oob message" I've tried
Googling ever piece of that message looking for some answer but there are literally 0 results. I was hoping someone here might have an answer.
thanks
KC
Response to comment:
The three calls are
-(IBAction)SendMessage
{
NSData* aData = [[NSData alloc] initWithData:[typeText.text dataUsingEncoding: NSUTF8StringEncoding]];
NSUTF8StringEncoding];
[self sendDataToPeers:aData];
}
-(void)sendDataToPeers:(NSData*)data
{
NSError* err;
BOOL didSend = [self.mySession sendDataToAllPeers:data withDataMode:GKSendDataReliable error:&err];
}
-(void) receiveData:(NSData*)data fromPeer:(NSString*)peer inSession:(GKSession*)session context:(void*)context
{
NSString* text = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]autorelease];
self.displayText.text = text;
}
I am also doing iphone to iphone with Wifi and GKSession. After aborted sessions (aka debugging or crash) Bonjour (or GKsessions) seem to get confused and this same scenario happens to me. With OS 3.x there was no message, just the hang. With OS 4.x I get the message "GCKSessionEvent_IncomingOOBPacket...". I have no idea what this means, but restarting the GKsession or reconnecting or sometimes just waiting solve the problem. I suspect might be a buffer full on outbound data due to messed up peers/receivers.
Kendrick, assuming you are using the 4.0 SDK, then you may be SOL on this. GKSession has a number of show-stopper bugs in the 4.0 SDK (crashes, errors, slowness) that were introduced recently. This message is due to one of them. I know because I was about to submit my GameKit app when they released 4.0 and now I'm waiting for 4.1 so I can submit it. The 4.1 Beta does fix a number of these issues, but it still doesn't work the way it worked on 3.1.3, sadly.
I'm building a program, and I'm quite confident using Objective-C, but I don't know how to programmatically download a file from the web and copy it on the hard drive.
I started with :
NSString url = #"http://spiritofpolo.com/images/logo.png";
NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
But then I don't know what to do with the data... that sucks, no ;)
Can somebody help?
You're close; the last thing you need is a call to -[NSData writeToFile:atomically:].
While that approach, with the final step provided by fbrereto, will work, it does not handle failure gracefully (indeed, it does not handle any sort of failure at all) and will block your application for the duration of the download.
Use NSURLDownload instead. It requires more code, but broken network connections, cut-off downloads, and inaccessible destination paths will not (necessarily) silently break your app.