Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning iOS 4 Application Development
|
BOOK: Beginning iOS 4 Application Development
This is the forum to discuss the Wrox book Beginning iOS 4 Application Development by Wei-Meng Lee; ISBN: 978-0-470-91802-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning iOS 4 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 12th, 2011, 12:49 PM
Authorized User
 
Join Date: Feb 2011
Posts: 13
Thanks: 5
Thanked 0 Times in 0 Posts
Default Ch.5 p139; "Detecting th Device"; How w/SDK4.2?

Hi, can anyone help?
I've worked through the Try It Out "Detecting the Device" & find that "UI_USER_INTERFACE_IDIOM()", used in the if condition to test for the device platform ("UIUserInterfaceIdiomPad") is no longer used in SDK 4.2.
Commenting in UIDevice.h says that "you may use -[UIDevice userInterfaceIdiom] directly."

I get the idea, well, sort of, & have tried to come up a way to write the if() condition but no luck so far. I'm used to PHP so the whole Obj C messaging thing is still weird for me. Haven't grokked it to where I can look at the declaration & necessarily know how to write what I need. (I was able to get the model string, w00t, but that's not a terribly good substitute.)

Here's the code from the book, used in MyiPhoneAppViewController.m :
Code:
 
	NSString *str;
	if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
		str = [NSString stringWithString:@"Running as an iPad application"];
	} else { 
		str = [NSString stringWithString:
					@"Running as an iPhone/iPod touch application"];
	}
Looking forward to this being second nature, but I ain't there yet!

Much thanks!
Chet
 
Old February 12th, 2011, 09:07 PM
Friend of Wrox
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

I don't have the book, so I can't comment directly on the try it out, but to detect the device using UIDevice:

Code:
UIDevice *current = [UIDevice currentDevice];
	if (current.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
		NSLog(@"it is an iPad");
	}
	else {
		NSLog(@"it is an iPhone or iPod");
	}
It is basically what the macro UI_USER_INTERFACE_IDIOM() does.


I didn't seen any indication that UI_USER_INTERFACE_IDIOM() is deprecated in 4.2. The macro is still in the Documentation

#define UI_USER_INTERFACE_IDIOM() \
([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ? \
[[UIDevice currentDevice] userInterfaceIdiom] : \
UIUserInterfaceIdiomPhone)

and works as expected.
The typedef returned is UIUserInterFaceIdiom and is either
UIUserInterfacePhone (which is integer constant 0)
or
UIUserInterfacePad (which is integer constant 1)

The result of using the macro (as in your code) or the property is the same.
Bob
The Following User Says Thank You to thepianoguy For This Useful Post:
gNotapipe (February 14th, 2011)
 
Old February 14th, 2011, 01:08 PM
Authorized User
 
Join Date: Feb 2011
Posts: 13
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Thanks, Bob!
Your post was very helpful to me. First, because I see much now the accessing of object properties & interpreting the class declarations. Second, because of the example of using the NSLog statement & console as the equivalent of the 'throw in a quick echo statement' I've been wanting. The book had mentioned this briefly, but not in the context of debugging.

I no doubt used too strong a word in "deprecated". I suppose there would have been at least a warning if it was. Perhaps 'outmoded' is more what I meant. UI_USER_INTERFACE_IDIOM() doesn't cause problems in 4.2 from what I'm seeing, but neither does it do anything. At least that's what I seem to be seeing. I'm not able to run the book's code as I haven't downloaded SDK 3.2 and so just get a "Base SDK missing" error.

I'll be working through the chapter again though, I'm doing this w/ everything, so perhaps things will become more clear over time. Certainly in trying to figure this out, & thanks to your comments, my understanding has grown considerably.

FWIW, I'm another diving into Obj-C, frameworks, iOS all at once guy. Hasn't proved too overwhelming so far, just a bit, umm, 'massive'... ;)

Thanks again!
Chet
 
Old February 14th, 2011, 02:31 PM
Friend of Wrox
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

As I said, I do not have the book, but a previous incarnation that most of this book's material is identical to. This section is not in the other book. I downloaded the Chapter 5 examples to check them out.
The (UI_USER_INTERFACE_IDIOM() macro appears to do nothing until you upgrade the current target for iPad. It returns 0 (iPhone) regardless of the simulator selected. After upgrading the current target for iPad, running in the simulator gives the correct response for the if statement, depending on which simulator you choose.

To use the downloaded project, (I used the one called MyiPhoneApp in the source code download to test) open it in Xcode and choose Project>Edit Active Target appName (MyiPhoneApp in this case) and under Architectures change the Base SDK to Latest iOS (it will initially say <multiple>) Close the project and reopen it. In the Groups & Files pane open the Target disclosure triangle and select (single click) the app (again, MyiPhoneApp in this case). Go back to the Project menu and choose Upgrade Current Target for iPad. From the window that opens choose whether you want a single universal app or two separate ones.
Changing the Base SDK from the top level of the Groups & Files pane and Get Info is not sufficient. I would update the Base SDK in both places.


Bob
The Following User Says Thank You to thepianoguy For This Useful Post:
gNotapipe (February 14th, 2011)
 
Old February 15th, 2011, 12:12 AM
Authorized User
 
Join Date: Feb 2011
Posts: 13
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Well, having reworked every step in the chapter to this point, and what you detailed above multiple times w/ no alerts appearing, nor output to the console after I added a NSLog statement, I finally, finally! looked happened to notice that hmm, maybe?, the #if condition began not w/ a single underscore, but two? As in not:
#if (_IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)
but:
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)
& Thus, shazzam, it worked.

D'oh!!!!!!! But damn easy to miss in the printed text as there's no space between them, & I have these aging eyes. (Though code hinting wasn't showing it either, & still doesn't, for whatever reason.)

Which you would I imagine have spotted immediately had I included that line in my original post. A lesson for the future for me!

& What the hey, I learned a helluva lot through this process,
due in no small part to yourself. Thx again!
Chet
 
Old February 15th, 2011, 08:39 AM
Friend of Wrox
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

Glad you are getting your head wrapped around it. The leading double underscore is visible in the source code download, and in the various framework header files (i.e. UIViewController.h) but I can see how it would be difficult to perceived on the printed page (or this webpage __ for that matter)
The magic of autocompletion does take place with the leading double underscore. (When you say code hinting doesn't work, are you saying that it is not auto-completing for you? It is for me) When autocomplete doesn't jump in, I usually take this as a hint that something may be taking the wrong path.
Bob
 
Old February 15th, 2011, 05:17 PM
Authorized User
 
Join Date: Feb 2011
Posts: 13
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Yes, it wasn't autocompleting that term. It was showing a fairly extensive listing of other terms when I hit esc. When autocompleting does & does not pop-up w/ suggestions is sometimes a bit mysterious for me still. I have learned that I can often get to what I want faster by hitting esc, though, & as part of that see & start getting acquainted w/ some of the related methods, properties, etc. I follow what you're saying about soething may be taking the wrong path; it seems at times though that it just doesn't find stuff. But this could be my newbness, likely is at least part of the time.
This is of secondary concern for me at this point though, plenty else to study, & the 'code sense' (or whatever xcode calls it) is gradually revealing its various easter eggs.





Similar Threads
Thread Thread Starter Forum Replies Last Post
MSXSL gives error message for "for" inside "select" ilyaz XSLT 1 December 9th, 2010 05:02 PM
Difficulties with "web.config" and "ASPNETDB" CFRham BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 2 July 3rd, 2010 10:19 AM
How to theme the "Browse" button of "FileUpload" control? varunbwj BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 October 14th, 2009 01:22 AM
Add a CheckBox DataColumn to my DataGridView, Null format: "" or "True" but Error: F ismailc C# 2005 0 September 25th, 2009 04:56 AM
Code not going as planned: "icicle" vs "savedinstancestate" joopthecat BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 May 3rd, 2009 03:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.