08-04-2010, 04:11 AM
#1 (permalink )
Elegance is Infinite
iPhone Dev SDK Supporter
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
Ip address drive
In some apps I've seen on the app store, like:
for i: Development Editor for the iPad they offer a feature where in your browser anywhere you can visit an address (the iPad) and exchange files with the app. I'm looking to integrate this into my iPad app.
The reason for posting here, is I have NO idea where to start on this. I appreciate your help!
If someone here is very comfortable with doing this, I'd be willing to pay you to spend some time helping me with it.
Looking forward to all your help!
08-04-2010, 08:39 AM
#2 (permalink )
Registered Member
Join Date: Nov 2009
Posts: 580
The basic idea is to create an http server running in the app that can handle requests for sending or receiving files. Fortunately, like many of these commonly needed tasks, there's a good chance that someone else has already done it for you -- check out Robin Lu's
cocoa-web-resource and see if that will do what you need.
08-04-2010, 04:40 PM
#3 (permalink )
Elegance is Infinite
iPhone Dev SDK Supporter
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
thanks chris.
I'm getting this warning:
Code:
format not a string literal and no format arguments
for this code:
Code:
NSString *message = @"Attempting to connect without a delegate. Set a delegate first.";
[NSException raise:AsyncSocketException format:message];
what can I do to get rid of the warning.
08-04-2010, 04:58 PM
#4 (permalink )
Registered Member
Join Date: Nov 2009
Posts: 580
Quote:
Originally Posted by
TapTouchClick
thanks chris.
I'm getting this warning:
Code:
format not a string literal and no format arguments
for this code:
Code:
NSString *message = @"Attempting to connect without a delegate. Set a delegate first.";
[NSException raise:AsyncSocketException format:message];
what can I do to get rid of the warning.
Try:
Code:
[NSException raise:AsyncSocketException format:@"%@", message];
I think that should get rid of it.
08-04-2010, 05:20 PM
#5 (permalink )
Elegance is Infinite
iPhone Dev SDK Supporter
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
thanks, again! one more thing.
Code:
NSDictionary *fileAttributes = [[NSFileManager defaultManager] fileAttributesAtPath:filePath traverseLink:NO];
is deprecated. What should I replace it with?
Hopefully this will be the last.
08-04-2010, 06:29 PM
#6 (permalink )
Registered Member
Join Date: Nov 2009
Posts: 580
Quote:
Originally Posted by
TapTouchClick
thanks, again! one more thing.
Code:
NSDictionary *fileAttributes = [[NSFileManager defaultManager] fileAttributesAtPath:filePath traverseLink:NO];
is deprecated. What should I replace it with?
Hopefully this will be the last.
That sounds like a great question for the
NSFileManager Class Documentation .
08-04-2010, 08:50 PM
#7 (permalink )
Elegance is Infinite
iPhone Dev SDK Supporter
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
before posting that I attempted making that line read:
Code:
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
but it didn't seem to work. It just hangs when your uploading something.
Last edited by TapTouchClick; 08-04-2010 at 08:52 PM .
08-04-2010, 11:36 PM
#8 (permalink )
Elegance is Infinite
iPhone Dev SDK Supporter
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
when I start a new project I get this warnining:
Code:
warning: no rule to process file '$(PROJECT_DIR)/docroot/jquery.js ' of type sourcecode.javascript for architecture i386
how can I fix this?
08-05-2010, 09:04 AM
#9 (permalink )
Registered Member
Join Date: Nov 2009
Posts: 580
Quote:
Originally Posted by
TapTouchClick
before posting that I attempted making that line read:
Code:
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
but it didn't seem to work. It just hangs when your uploading something.
Are you sure that this line is actually the problem with the upload? Does it resume working if you restore the deprecated line? Try putting in a breakpoint and making sure the contents of fileAttributes are correct.
FYI, I'm not familiar with this library beyond the fact that it exists, so I can't really offer much insight if things don't work as advertised. You'll need to contact the original author or spend some time going through the code yourself.
08-05-2010, 09:08 AM
#10 (permalink )
Registered Member
Join Date: Nov 2009
Posts: 580
Quote:
Originally Posted by
TapTouchClick
when I start a new project I get this warnining:
Code:
warning: no rule to process file '$(PROJECT_DIR)/docroot/jquery.js ' of type sourcecode.javascript for architecture i386
how can I fix this?
This happens because Xcode mistakenly thinks that the javascript file is something that it should be trying to compile instead of a resource that just needs to be included in the app bundle. If you click the triangle next to your target in the project tree window and look in the "Compile Sources" folder, you should see the jquery.
js file is there. Just move it from there to the "Copy Bundle Resources" folder instead and the warning should go away.
08-05-2010, 02:36 PM
#11 (permalink )
Elegance is Infinite
iPhone Dev SDK Supporter
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
I made a new project. and now something odd is happening. The whole thing works exactly like the old project, but when you visit the IP address in the browser, its completely white. DO you think you can either look through my code, or help me find out what making it white.
Also, I retested it, and I'm 100% sure that:
Code:
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
causes the simulator to hang and never start the connection.
08-05-2010, 03:56 PM
#12 (permalink )
Elegance is Infinite
iPhone Dev SDK Supporter
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
I did some snooping around and I found it returns a 404 not found because of this:
Code:
- (void)handleResponse:(NSObject<HTTPResponse> *)rsp method:(NSString*)method
{
// Respond properly to HTTP 'GET' and 'HEAD' commands
httpResponse = [rsp retain];
UInt64 contentLength = [httpResponse contentLength];
if(contentLength == 0)
{
NSLog(@"conlen = 0");
[self handleResourceNotFound];
[httpResponse release];
httpResponse = nil;
return;
}
// Check for specific range request
NSString *rangeHeader = [(NSString *)CFHTTPMessageCopyHeaderFieldValue(request, CFSTR("Range")) autorelease];
BOOL isRangeRequest = NO;
if(rangeHeader)
{
if([self parseRangeRequest:rangeHeader withContentLength:contentLength])
{
isRangeRequest = YES;
}
}
CFHTTPMessageRef response;
if(!isRangeRequest)
{
// Status Code 200 - OK
response = CFHTTPMessageCreateResponse(kCFAllocatorDefault, 200, NULL, kCFHTTPVersion1_1);
NSString *contentLengthStr = [NSString stringWithFormat:@"%qu", contentLength];
CFHTTPMessageSetHeaderFieldValue(response, CFSTR("Content-Length"), (CFStringRef)contentLengthStr);
}
else
{
if([ranges count] == 1)
{
response = [self prepareUniRangeResponse:contentLength];
}
else
{
response = [self prepareMultiRangeResponse:contentLength];
}
}
// If they issue a 'HEAD' command, we don't have to include the file
// If they issue a 'GET' command, we need to include the file
if([method isEqual:@"HEAD"])
{
NSData *responseData = [self preprocessResponse:response];
[asyncSocket writeData:responseData withTimeout:WRITE_HEAD_TIMEOUT tag:HTTP_RESPONSE];
}
else
{
// Write the header response
NSData *responseData = [self preprocessResponse:response];
[asyncSocket writeData:responseData withTimeout:WRITE_HEAD_TIMEOUT tag:HTTP_PARTIAL_RESPONSE_HEADER];
// Now we need to send the body of the response
if(!isRangeRequest)
{
// Regular request
NSData *data = [httpResponse readDataOfLength:READ_CHUNKSIZE];
[asyncSocket writeData:data withTimeout:WRITE_BODY_TIMEOUT tag:HTTP_PARTIAL_RESPONSE_BODY];
}
else
{
// Client specified a byte range in request
if([ranges count] == 1)
{
// Client is requesting a single range
DDRange range = [[ranges objectAtIndex:0] ddrangeValue];
[httpResponse setOffset:range.location];
unsigned int bytesToRead = range.length < READ_CHUNKSIZE ? range.length : READ_CHUNKSIZE;
NSData *data = [httpResponse readDataOfLength:bytesToRead];
[asyncSocket writeData:data withTimeout:WRITE_BODY_TIMEOUT tag:HTTP_PARTIAL_RANGE_RESPONSE_BODY];
}
else
{
// Client is requesting multiple ranges
// We have to send each range using multipart/byteranges
// Write range header
NSData *rangeHeader = [ranges_headers objectAtIndex:0];
[asyncSocket writeData:rangeHeader withTimeout:WRITE_HEAD_TIMEOUT tag:HTTP_PARTIAL_RESPONSE_HEADER];
// Start writing range body
DDRange range = [[ranges objectAtIndex:0] ddrangeValue];
[httpResponse setOffset:range.location];
unsigned int bytesToRead = range.length < READ_CHUNKSIZE ? range.length : READ_CHUNKSIZE;
NSData *data = [httpResponse readDataOfLength:bytesToRead];
[asyncSocket writeData:data withTimeout:WRITE_BODY_TIMEOUT tag:HTTP_PARTIAL_RANGES_RESPONSE_BODY];
}
}
}
CFRelease(response);
}
how can I determine why content length is 0? Is this just feedback or is this what's causing it? This is really odd to me.
content length is based off of this function:
Code:
- (UInt64)contentLength
{
NSLog(@"trys to check");
//NSDictionary *fileAttributes = [[NSFileManager defaultManager] fileAttributesAtPath:filePath traverseLink:NO];
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
NSNumber *fileSize = [fileAttributes objectForKey:NSFileSize];
NSLog(@"file-size: %d",fileSize);
return (UInt64)[fileSize unsignedLongLongValue];
}
but it doesn't even get called because "trys to check" never appears in the console. Is this some leak, or what? I'm really in need of help here.
Last edited by TapTouchClick; 08-05-2010 at 04:02 PM .
08-05-2010, 04:09 PM
#13 (permalink )
Elegance is Infinite
iPhone Dev SDK Supporter
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
Also, something REALLY weird happens. in this function:
Code:
- (NSObject<HTTPResponse> *)httpResponseForURI:(NSString *)path
{
// Override me to provide custom responses.
NSString *filePath = [self filePathForURI:path];
NSLog(@"fp: %@",filePath);
if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
return [[[HTTPFileResponse alloc] initWithFilePath:filePath] autorelease];
}
return nil;
}
NSLog(@"full: %@",fullPath);
}
the NSLog prints this:
Code:
fp: .../iPhone Simulator/4.0/Applications/61C282E2-9F1F-4E54-8975-14BF3F316475/tmp/docroot/favicon.ico
and NO where in the code does it say favicon.ico
I don't understand this at all, why does it work in one project, but then when I duplicate word for word over into another project all hell breaks loose.
08-05-2010, 06:39 PM
#14 (permalink )
Elegance is Infinite
iPhone Dev SDK Supporter
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
Wow! restarted from scratch one more time, and everything works! even: NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
thanks ChrisL, if you give me a donate link i'll send you $5.
08-05-2010, 10:30 PM
#15 (permalink )
Registered Member
Join Date: Nov 2009
Posts: 580
Quote:
Originally Posted by
TapTouchClick
Wow! restarted from scratch one more time, and everything works! even: NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
Glad you were able to get it.
Quote:
thanks ChrisL, if you give me a donate link i'll send you $5.
I really appreciate the gesture, but it's not necessary. Put it towards a reference book or something else that would be useful to you.
08-09-2010, 08:35 PM
#16 (permalink )
Elegance is Infinite
iPhone Dev SDK Supporter
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
How can I set this up so you can mount the drive to your mac using Finder?
Thanks
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs