Monday, December 27, 2010

Update to ATV2 problem - Fixed

After a few more hours of troubleshooting and reading I found there is a feature in DNSMasq that protects you from a DNS Rebind attack.  Unfortunately, the way Netflix works it uses something that looks just like that, so your DNS queries don't work and you get no video.

With most setups you could change the DNS server of your Apple TV (and iPhones, because this happens on them also) to the google address (8.8.8.8).  Of you can look at your router to see what your ISPs DNS server is and use that.

If you are using DD-WRT, you can upgrade (or look, you might already have this feature if you upgraded in the last 2 months) to a version that has "No DNS Rebind" on the services page in the DNSMasq section.  This turns off that security feature.  Below is a picture with it turned off.  Be sure to reboot your router after you make this change.

If you are using DNSMasq on something else, look into a way to turn off DNS Rebind protection.  There are several commands out there for Linux based systems, but I don't have the time to go check them.  You can start at this link that has some of the commands:
http://www.dd-wrt.com/phpBB2/viewtopic.php?p=518676&sid=26f3585e507c4a2acf83f3fb817971a1 



Sunday, December 26, 2010

Apple TV 2 problems

I've been working on the "no netflix videos" for a few days now, and finally tried something new and got it working.  Prior to this I could browse everything, but trying to play would spin the pinwheel, and then go back to the movie description window.  Now everything works great and I can stream movies and TV shows from Netflix.

Here is what I did.
1.  I connected my ATV2 directly to the back of my cable modem.  This worked.
Going with the idea that maybe there is a connection that is being started from Netflix I decided to try normal port forwarding things on the router.
2.  I setup UPNP.  That didn't work.
3.  I setup a DMZ (basically it port forwards all incoming new connections) to the ATV2.  That didn't work either.

My final setup now until Apple/Netflix/Me figure out what's wrong and fix it is the following:
I used an old Ethernet switch, and have the these thigns connected to it:
1.  Cable modem
2.  Linksys E3000 - WAN Port (my main Internet router for my house with lots of stuff behind it)
3.  ATV2 Ethernet port

The big difference in this setup is that the ATV2 has a public Internet address as opposed to a private address.  If you have more than one Internet device in your house, you are probably using private addressing.  Your ATV probably has an address that starts with 192.168.x.x where x any number between 1 and 254.

Wednesday, May 12, 2010

How to know in what row an accessory was clicked - TableView

I was creating a grouped tableview that had detail disclosures on some of the cells that should then open a new view and make some changes. I'm using the following code to figure out what cell the accessory is in.

The key things to remember are the "accessoryButtonTappedForRowWithIndexPath" method, and then using the switch (indexPath.section) for the section and switch (indexPath.row) for the row.

The trick I used was the copy the "switch" information directly from the method I used to build the table in the first place. I took out the logic I used, but left in a comment to help me remember what line was what. example: // Description

Happy coding!

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {

ServerDescriptionView *serverDescriptionView = [[ServerDescriptionView alloc] initWithNibName:@"ServerDescriptionView" bundle:nil];

serverDescriptionView.profile = profile.agencyPolicyName;

ServerActiveServerView *serverActiveServerView = [[ServerActiveServerView alloc] initWithNibName:@"ServerActiveServerView" bundle:nil];

serverActiveServerView.profile = profile.agencyPolicyName;


switch (indexPath.section) {

case 1:

switch (indexPath.row) {

case 0:

// Description

[[self navigationController] pushViewController:serverDescriptionView animated:YES];

[serverDescriptionView release];

break;

case 1:

// Active Server

[[self navigationController] pushViewController:serverActiveServerView animated:YES];

[serverActiveServerView release];


break;

}

break;

case 2:

switch (indexPath.row) {

case 0:

// Server Power

break;

case 1:

// Unbind from the Template

break;

case 2:

// Reset UUID

break;

}

}

}

Tuesday, May 11, 2010

Calling methods in another class file

Now that I have my app doing quite a few things I'm starting to realize that I should have created one central place to put a bunch of functions and then call them from different views. So, I spent some time in google (because I don't have any iPhone programming books, nor do I know how to program object oriented stuff) and found a few different way to do this. Actually, they are just variations of the same thing. I'll show how I'm doing it in my code now.

In the YourFunctions.h file of the new class:

- (void) showAlert:(int)errorNumber;


In the YourFunctions.m file of the new class:

- (void) showAlert:(int)errorNumber {

UIAlertView *error = [[UIAlertView alloc] initWithTitle:[[NSString alloc] initWithFormat:@"Error: %D", errorNumber]

message:[[NSString alloc] initWithFormat:@"This is an error"]

delegate:nil

cancelButtonTitle:@"OK"

otherButtonTitles: nil];

[error show];

[error release];

}


In the YourView.m file you are calling this new method from:

#import "YourFunctions.h"


// As a test I attached a button to this action.

- (IBAction)showAnAlert {

int errorNumber = 22;

YourFunctions *yourFunctions = [[YourFunctions alloc] init];

[yourFunctions showAlert:errorNumber];

}



Tuesday, March 23, 2010

iPhone Sequential Execution

Something that I've found a little odd in iPhone code is that things don't always execute sequentially. Actually, I'm sure they do, but because they all seem to load at once they don't seem like it. I found a great method of something executing right away. By encapsulating a method in the following function, things before it run, and then this executes and runs. This is especially useful to be so that I can have an activity indicator (spinning ball) run while this happens in the background.

// Start up our activity indicator while we collect the data

[self startActivityIndicator];

// Run the loadData method right now

[self performSelector:@selector(loadDataInBackground) withObject:nil afterDelay:0.0];


I can then end the Activity Indicator when I get to the end of the "loadDataInBackground" method. If we just call both of the methods, the ActivityIndicator doesn't display until just as the loadData method ends.


-Tige

Wednesday, February 03, 2010

Modifying add hoc users

If you add users to your original beta you will want to know this. From the iPhone developer page, go to the following:
Provisioning -> Distribution
Edit -> Modify (assuming you have one, or make one at this point)
Select your new people (I name this with the beta they are in as part of their name for reference)
Submit
You will need to download this file (it should say pending right now).

Note: Don't do like me and go to another page for a second and then come back and forget to click the "distribution" tab and end up downloading my development certificate again and wondering what the heck was going on.

Now follow the directions below. Good luck!

-Tige




This is a GREAT write up on doing add hoc and I did a direct Cut and Paste from the blog at JohhnyWorks:
http://johnehartzog.com/2009/04/iphone-app-ad-hoc-gotchas/

"One more thing that caught me over and over again: don’t forget to increment the version number in your info.plist file before giving Ad Hoc users a new copy! iTunes is really sneaky about what happens here…in both cases it says the application is already installed, and asks if you want to replace it, but if you try to replace with the same or lower version number, it won’t actually do anything.

If you are getting

Application was not installed on the iPhone because it could not be verified.

then your profile isn’t valid and you should check out this post. This biggest thing to remember is

  1. Delete all the profiles stored in ~/Library/MobileDevice/Provisioning Profile.
  2. Double click your .mobileprovision file and it will get loaded into XCode - There is a chance that it will get loaded by another application. If that is the case, right-click it and open it with xcode.
  3. Quit XCode completely. I’m not sure why this is necessary, but often XCode refuses to build unless it starts up with the profile already ready.

Lastly, ensure not only that Entitlements.plist is included in your project (click File, New File, Code Signing, Entitlements), and that get-task-allow is unchecked, but in your “Ad Hoc” build profile (Project, Edit Active Target) expand the list to “All Settings” make sure the “Code Signing Entitlements” field is filled out with your “Entitlements.plist”."

Monday, February 01, 2010

Add Hoc distribution for iPhone App

Now to create the bundle to give to people and install in iTunes.

Get your .app file that was created. Be sure you have all debugging turned off and not spitting out any junk you used for testing, etc. I also changed the version number of the application in the .plist file for the app and on the info screen so people would know it's beta and not get confused or something later.

For people to install the application they need two files. For a Mac, they just need the .app file and the .mobileprovision file. That said, I'm creating the Windows version for everyone for two reasons. I only have to distribute one package, and two I can put the icon in iTunes with the Windows method and I can't figure out how to do that with the Mac method. So, here is the Windows Method. There are lots of version of this on the web and this is what works for me.

This is a very informative post:
http://iphoneinaction.manning.com/iphone_in_action/2009/11/creating-an-ad-hoc-distribution.html

Now for the distribution files.

  • Create a directory for your distribution, we'll call it myApp
  • Create a folder in that folder called myApp/Payload
  • Put a copy of myApp.app in Payload
  • Put a copy of the file you want displayed in Itunes in the myApp folder
  • This file should be called iTunesArtwork, no extension (I used a PNG, the same one as my apps icon)
  • Create a .ipa file using the following: zip -r myAppBeta.ipa Payload
  • Add the artwork to the .ipa file: zip -r myAppBeta.ipa iTunesArtwork

You're done. Now send everyone in the beta test the myAppBeta.ipa file, and the myApp.mobileprovision file. All they need to do is drag both files into iTunes and sync their phone. You probably should try it first before sending it out. :)

iPhone app, ready for Beta

My app is finally in a condition that I feel it's safe to give to people so they can beta test it and find the real problems. :) I was having an issue with Build-Run once I had added my new signature file, etc. Here is the error: The executable was signed with invalid entitlements
I was also getting an error when trying to install it via iTunes that the phone was not entitled to run the application.

This is the information from StackOverflow with some minor changes:
http://stackoverflow.com/questions/1074546/the-executable-was-signed-with-invalid-entitlements

For Ad Hoc Distribution, complete the following:

  • In the File Menu, select New File -> iPhone OS -> Code Signing -> Entitlements. Name the file “Entitlements.plist" and click ‘Finish’. This creates a copy of the default entitlements file within the project.
  • Select the new Entitlments.plist file and uncheck the “get-task-allow” property. Save the Entitlements.plist file.
  • Select the Target and open the Project -> Edit Project Settings -> Build settings inspector. In the ‘Code Signing Entitlements’ build setting, type in the filename of the new Entitlements.plist file including the extension. There is no need to specify a path unless you have put the Entitlements.plist file somewhere other than the top level of the project

Sunday, January 17, 2010

Text Fields and dismissing the keyboard

I was going back and making changes to my text fields and keyboard dismissing and wanted to move to the next field only if that field was blank. I relized then, that I had not taken any notes here on how to dismiss a keyboard, or how to assign a new text field. Here is the code to dismiss a field, and then assign the next one. I'll just write some if statements to figure out the order in which I want them to populate if the user needs to enter them all.

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {

if (theTextField == userName) {

[userName resignFirstResponder];

[userPassword becomeFirstResponder];

}

if (theTextField == userPassword) {

[userPassword resignFirstResponder];

[serverAddress becomeFirstResponder];

}

if (theTextField == serverAddress) {

[serverAddress resignFirstResponder];

}

return YES;

}



Ok, I wrote the if statements before I even finished writing this blog. It's messy, so if you know a bette/faster way to do this, do it your way!


- (BOOL)textFieldShouldReturn:(UITextField *)aTextField {

if (aTextField == userName) {

[userName resignFirstResponder];

if ([userPassword.text length] == 0) {

[userPassword becomeFirstResponder];

} else if ([serverAddress.text length] == 0) {

[serverAddress becomeFirstResponder];

}

}

if (aTextField == userPassword) {

[userPassword resignFirstResponder];

if ([serverAddress.text length] == 0) {

[serverAddress becomeFirstResponder];

}

}

if (aTextField == serverAddress) {

[serverAddress resignFirstResponder];

}

return YES;

}

Thursday, January 14, 2010

Working with SQL Databases on iPhone

I'm using a small sqlite database for my iPhone app and was having problems with the data. I was making changes to the database in either CLI or in Firefox SQLite Manager, deleting the database file from my iPhone project, and copying the new file in. It would never use the new data, only the old data was being accessed. I finally figured out what was going on because there was not enough rows when I was stepping through it and set out looking for an answer. Below is the first hit I found and it answered it perfectly.

Short answer: It get's cached like data for a normal application. Go look in your folder for the iPhone Simulator/USR/Applications and you will be able to delete it from there. Then compile your code again and it should be working.

Monday, January 11, 2010

Refreshing views while using a Tab Bar on the iPhone

In my tab bar based iPhone application I had a view that would connect to a web service and pull down the requested data. It would then use that data to populate labels and text fields on other views. I had it working for the first time using "- (void)viewDidLoad", but was not able to get it to update when I would go back to the main view and refresh the information.

I finally found that the viewWillAppear method just didn't have a place holder but I could add it and use it. So, just add the following code to the .m file controlling your view and it will update every time you switch back to it.

- (void)viewWillAppear:(BOOL)animated {

// Do stuff here

[super viewWillAppear:animated];

}


Thursday, January 07, 2010

Handling iPhone errors part two

Now that I can make a pop-up message I wanted to clean up the code and do all of my error processing from one place. To this end I removed all of the error handling I was doing and instead changed it so my individual functions would return a value. The number 0 if everything was ok, and a number that would signify the error type if everything was not ok. I had about 15 possible errors at the time so I gave them all numbers and converted my functions from -(void) to -(int) and added the numbers to the return lines. Below you will see an example of the code and how I'm now processing the errors. Everything works fine, but if there is a better way to do this, please let me and everyone else know.

// Header file

- (IBAction)refreshInformation:(id)sender;

- (int)verifyUserInput;

- (void)handleErrors:(int)errorNumber;


// Call the function to check user input, and then pass the results to the error checking //function

- (IBAction)refreshInformation:(id)sender {

NSInteger funcReturn = 0;


// Verify they have entered everything we need to get the information

funcReturn = [self verifyUserInput];


// Did we have any errors?

if (funcReturn) {

[self handleErrors:funcReturn];

}

}



// Function to check the user input

- (int)verifyUserInput {


// Initialize some local variables with the input from the user

NSString *nameString = userName.text;

NSString *passString = userPassword.text;

NSString *serverString = serverAddress.text;

// Verify that people are putting the right stuff into the fields

if ([nameString length] == 0) {

return 11;

} else if ([passString length] == 0) {

return 11;

} else if ([serverString length] == 0) {

return 11;

}


return 0;

}


// Function to process the error numbers

- (void)handleErrors:(int)errorNumber {

NSString *errorText;

switch (errorNumber) {

case 11:

errorText = @"All fields are required";

break;

case 21:

errorText = @"Authentication failed";

break;

case 22:

errorText = @"System login failure";

break;

case 23:

errorText = @"Read-Only user required";

break;

case 24:

errorText = @"Network connection failed";

break;

}


UIAlertView *error = [[UIAlertView alloc] initWithTitle:[[NSString alloc] initWithFormat:@"Error: %D", errorNumber]

message:[[NSString alloc] initWithFormat:@"%@", errorText]

delegate:nil

cancelButtonTitle:@"OK"

otherButtonTitles: nil];

[error show];

[error release];

}


Wednesday, January 06, 2010

Handling Errors on the iPhone

I read that you need to have a popup error if your application can't get to a network and it's required, so I did some quick checking on how to do that and here is the code I found. Very simple to use and modify to add specific errors. Just place this into a function and call it, or put it right into your code where an error occurs.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"

message:@"This is the error or get a string"

delegate:nil

cancelButtonTitle:@"OK"

otherButtonTitles: nil];

[alert show];

[alert release];


iPhone TabBar icons



Happy New Year everyone!

As with all fun projects, I've taken a new tactic at how to do my iPhone application. It now includes a tab bar at the bottom for switching between pages. I now had a new problem. All of the icons were coming up as grey blobs in the bar and it took me a while to figure out how to fix it. I never really found a good answer on the internet, so it's my own info here (not a link like normal).

I found that the icons should be 30x30 pixels and should be in grey scale. I also have found that anything that is colored shows up as a light grey. It doesn't seem to mater if this is white, grey, black, etc. Everything else should be transparent and that will will show up black.

The pictures above are black lines on a transparent background.

-Tige