iPhoneのサンプルプログラム

端末の識別

iphone.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
       <dict>
               <key>name</key>
               <string>takeda</string>
               <key>device_id</key>
               <string>412ca4263da13fe7b87cc10658cead8d9d5be699</string>
       </dict>
       <dict>
               <key>name</key>
               <string>yama</string>
               <key>device_id</key>
               <string>2986e2f8d4419aeb1635dcc9b22dadee768ea57e</string>
       </dict>
</array>
</plist>

DeviceList.h
#import <Foundation/Foundation.h>

@interface DeviceList : NSObject {
   NSArray *list;
}

- (id)init;
- (NSString *)search: (NSString *)iPhoneId;
- (void)dealloc;

@end

DeviceList.m
#import "DeviceList.h"

@implementation DeviceList

- (id)init
{
   if (self = [super init]) {
      NSString *path = [[NSBundle mainBundle] pathForResource:@"device" ofType:@"plist"];
      list = [NSArray arrayWithContentsOfFile:path];
   }

   return self;
}

- (void)dealloc
{
   [super dealloc];
}

- (NSString *)search:(NSString *)id
{
   for (NSDictionary *data in list)
   {
      NSString *name = [data objectForKey:@"name"];
      NSString *cur_id = [data objectForKey:@"device_id"];

      if ([cur_id isEqualToString: id]) {
         NSString *username = [[NSString alloc] initWithString:name];
         return username;
      }
   }

   return [[NSString alloc] initWithString:@"未登録"];
}

@end

DeviceChecker1ViewController.h
#import <UIKit/UIKit.h>
#import "DeviceList.h"

@interface DeviceChecker1ViewController : UIViewController {
   IBOutlet UILabel *labelMsg;
}

- (IBAction)onButton1;

@end

DeviceChecker1ViewController.m
#import "DeviceChecker1ViewController.h"

@implementation DeviceChecker1ViewController

- (void)didReceiveMemoryWarning {
   // Releases the view if it doesn't have a superview.
   [super didReceiveMemoryWarning];

   // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
   // Release any retained subviews of the main view.
   // e.g. self.myOutlet = nil;
}

- (void)dealloc {
   [super dealloc];
}

- (void)onButton1
{
   DeviceList *list = [[DeviceList alloc] init];

   UIDevice *dev = [UIDevice currentDevice];
   NSString *iPhoneID = dev.uniqueIdentifier;

   NSString *username = [list search:iPhoneID];
   NSString *msg = [NSString stringWithFormat:@"%@ さんのiPhoneです。", username];

   [labelMsg setText:msg];

   [username release];
   [list release];
}

@end

アプリのIcon(57x57)