Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-04-2010, 04:11 AM   #1 (permalink)
Elegance is Infinite
iPhone Dev SDK Supporter
 
TapTouchClick's Avatar
 
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
TapTouchClick is on a distinguished road
Send a message via AIM to TapTouchClick Send a message via Skype™ to TapTouchClick
Default 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!
__________________
Our website
TapTouchClick is offline   Reply With Quote
Old 08-04-2010, 08:39 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 580
ChrisL is on a distinguished road
Default

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.
ChrisL is offline   Reply With Quote
Old 08-04-2010, 04:40 PM   #3 (permalink)
Elegance is Infinite
iPhone Dev SDK Supporter
 
TapTouchClick's Avatar
 
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
TapTouchClick is on a distinguished road
Send a message via AIM to TapTouchClick Send a message via Skype™ to TapTouchClick
Default

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.
__________________
Our website
TapTouchClick is offline   Reply With Quote
Old 08-04-2010, 04:58 PM   #4 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 580
ChrisL is on a distinguished road
Default

Quote:
Originally Posted by TapTouchClick View Post
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.
ChrisL is offline   Reply With Quote
Old 08-04-2010, 05:20 PM   #5 (permalink)
Elegance is Infinite
iPhone Dev SDK Supporter
 
TapTouchClick's Avatar
 
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
TapTouchClick is on a distinguished road
Send a message via AIM to TapTouchClick Send a message via Skype™ to TapTouchClick
Default

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.
__________________
Our website
TapTouchClick is offline   Reply With Quote
Old 08-04-2010, 06:29 PM   #6 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 580
ChrisL is on a distinguished road
Default

Quote:
Originally Posted by TapTouchClick View Post
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.
ChrisL is offline   Reply With Quote
Old 08-04-2010, 08:50 PM   #7 (permalink)
Elegance is Infinite
iPhone Dev SDK Supporter
 
TapTouchClick's Avatar
 
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
TapTouchClick is on a distinguished road
Send a message via AIM to TapTouchClick Send a message via Skype™ to TapTouchClick
Default

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.
__________________
Our website

Last edited by TapTouchClick; 08-04-2010 at 08:52 PM.
TapTouchClick is offline   Reply With Quote
Old 08-04-2010, 11:36 PM   #8 (permalink)
Elegance is Infinite
iPhone Dev SDK Supporter
 
TapTouchClick's Avatar
 
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
TapTouchClick is on a distinguished road
Send a message via AIM to TapTouchClick Send a message via Skype™ to TapTouchClick
Default

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?
__________________
Our website
TapTouchClick is offline   Reply With Quote
Old 08-05-2010, 09:04 AM   #9 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 580
ChrisL is on a distinguished road
Default

Quote:
Originally Posted by TapTouchClick View Post
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.
ChrisL is offline   Reply With Quote
Old 08-05-2010, 09:08 AM   #10 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 580
ChrisL is on a distinguished road
Default

Quote:
Originally Posted by TapTouchClick View Post
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.
ChrisL is offline   Reply With Quote
Old 08-05-2010, 02:36 PM   #11 (permalink)
Elegance is Infinite
iPhone Dev SDK Supporter
 
TapTouchClick's Avatar
 
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
TapTouchClick is on a distinguished road
Send a message via AIM to TapTouchClick Send a message via Skype™ to TapTouchClick
Default

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.
__________________
Our website
TapTouchClick is offline   Reply With Quote
Old 08-05-2010, 03:56 PM   #12 (permalink)
Elegance is Infinite
iPhone Dev SDK Supporter
 
TapTouchClick's Avatar
 
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
TapTouchClick is on a distinguished road
Send a message via AIM to TapTouchClick Send a message via Skype™ to TapTouchClick
Default

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.
__________________
Our website

Last edited by TapTouchClick; 08-05-2010 at 04:02 PM.
TapTouchClick is offline   Reply With Quote
Old 08-05-2010, 04:09 PM   #13 (permalink)
Elegance is Infinite
iPhone Dev SDK Supporter
 
TapTouchClick's Avatar
 
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
TapTouchClick is on a distinguished road
Send a message via AIM to TapTouchClick Send a message via Skype™ to TapTouchClick
Default

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.
__________________
Our website
TapTouchClick is offline   Reply With Quote
Old 08-05-2010, 06:39 PM   #14 (permalink)
Elegance is Infinite
iPhone Dev SDK Supporter
 
TapTouchClick's Avatar
 
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
TapTouchClick is on a distinguished road
Send a message via AIM to TapTouchClick Send a message via Skype™ to TapTouchClick
Default

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.
__________________
Our website
TapTouchClick is offline   Reply With Quote
Old 08-05-2010, 10:30 PM   #15 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 580
ChrisL is on a distinguished road
Default

Quote:
Originally Posted by TapTouchClick View Post
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.
ChrisL is offline   Reply With Quote
Old 08-09-2010, 08:35 PM   #16 (permalink)
Elegance is Infinite
iPhone Dev SDK Supporter
 
TapTouchClick's Avatar
 
Join Date: Jan 2010
Location: Bay Area, CA
Posts: 677
TapTouchClick is on a distinguished road
Send a message via AIM to TapTouchClick Send a message via Skype™ to TapTouchClick
Default

How can I set this up so you can mount the drive to your mac using Finder?
Thanks
__________________
Our website
TapTouchClick is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 328
8 members and 320 guests
alexP, gordo26, headkaze, mistergreen2011, nobstudio, rayjeong, Sloshmonster, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:21 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0