Matt Brown – Journeys of a software engineer

July 18, 2009

How I got a new Apple 32GB 3GS iPhone for ~$30

Filed under: iPhone — Tags: — mattbsoftware @ 8:56 pm
Prereqs:
  • Have a 3G iPhone for 12-18 months
  • Pay AT&T more than $100 per month

I listed my 1 year old 3G 16GB for $300 on craiglist. Within 4 hours I had 40 offers, almost all saying “I have cash, where can we meet.” I got a little more than originally paid for the iPhone, in cash, and the buyer came to me.

Next, I went to the apple store and bought my phone for a net price of ~$30!!!!!
– $299 for 3GS/32GB
– $~30 fees
+$300 cash
—————
=$~30

April 29, 2009

Be Very Careful with iPhone Mobile Provisioning

Filed under: Apple, Certificates, iPhone, Mobile Provisioning — Tags: , , , — mattbsoftware @ 12:30 am

I have a new Mac Book Pro and have screwed it up twice by not carefully following instructions. I have been developing for iPhone with my iMac and wanted to be able to do the same on the MBP. At the end of both attempts my MBP could not see the iPhone, not even in iTunes. A reload of OS-X will bring the devices back, but may have other consequenses. I ultimately re-imaged my system and started over. Read on to avoid my pain.

The secret is to carefully, slowly follow the instructions.

This is super high level description, please read the Apple links below, they have the step-by-step instructions

These operations in the following order worked for me:

  1. Import private key for certificate – installed private key (double click *.p12 – add to login)
  2. Import certificate – installed cert – double click on *.cer – add to login
  3. Import mobile provision – drag and drop .mobileprovision file on to the xcode icon on the doc

Hints: store the above three files some where safe from destruction and prying hands. (Apple suggests an encrypted DMG)

I followed these steps:
1. Get your private key: http://developer.apple.com/iPhone/library/documentation/Xcode/Conceptual/iphone_development/128-Managing_Devices/devices.html#//apple_ref/doc/uid/TP40007959-CH4-SW8
2. Dev Certificate and Mobile provision: http://developer.apple.com/iPhone/library/documentation/Xcode/Conceptual/iphone_development/128-Managing_Devices/devices.html#//apple_ref/doc/uid/TP40007959-CH4-SW42

April 5, 2009

How to get the IP address of an iPhone OS v2.2.1

Filed under: iPhone, Objective-C — Tags: , — mattbsoftware @ 11:35 pm

Lately I have been struggling with an iPhone OS 2.2.1 app that needs to know the WiFi IP address of the iPhone. Unfortunately at the time the app runs it does not have internet access and thus I cannot use whatismyip.com.

With thanks to Erica Sadun (iPhone cookbook) and gandreas and valexa on the iPhone dev forums I was able to create the following function. The function iterates over the IPs of the phone using getifaddrs(&addrs). if getWiFiIPAddress finds "en0" in the list interface addresses (ifaddrs) it will return the ethernet adapter zero (en0) IP address as a NSSring*. If no address is found the function will return NULL.

//------- includes

#include <ifaddrs.h>
#include
<arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <arpa/inet.h>
#include <ifaddrs.h>

#if ! defined(IFT_ETHER)
#define IFT_ETHER 0x6/* Ethernet CSMACD */
#endif

//------- Implementation

- (NSString*)getWiFiIPAddress
{

BOOL success;
struct ifaddrs * addrs;
const struct ifaddrs * cursor;

success = getifaddrs(&addrs) == 0;
if (success) {
cursor = addrs;
while (cursor != NULL) {
if (cursor->ifa_addr->sa_family == AF_INET && (cursor->ifa_flags & IFF_LOOPBACK) == 0) // this second test keeps from picking up the loopback address
{
NSString *name = [NSString stringWithUTF8String:cursor->ifa_name];
if ([name isEqualToString:@"en0"]) { // found the WiFi adapter
return [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)cursor->ifa_addr)->sin_addr)];
}
}

cursor = cursor->ifa_next;
}
freeifaddrs(addrs);
}
return NULL;
}

PS: I need a better blog, that support snippets – comments?

Create a free website or blog at WordPress.com.