Get Mac Address iPhone

#include <sys/socket.h>
#include <sys/sysctl.h>
#include <net/if.h>
#include <net/if_dl.h>
....
- (NSString *)getMacAddress
{
  int                 mgmtInfoBase[6];
  char                *msgBuffer = NULL;
  size_t              length;
  unsigned char       macAddress[6];
  struct if_msghdr    *interfaceMsgStruct;
  struct sockaddr_dl  *socketStruct;
  NSString            *errorFlag = NULL;

  // Setup the management Information Base (mib)
  mgmtInfoBase[0] = CTL_NET;        // Request network subsystem
  mgmtInfoBase[1] = AF_ROUTE;       // Routing table info
  mgmtInfoBase[2] = 0;              
  mgmtInfoBase[3] = AF_LINK;        // Request link layer information
  mgmtInfoBase[4] = NET_RT_IFLIST;  // Request all configured interfaces

  // With all configured interfaces requested, get handle index
  if ((mgmtInfoBase[5] = if_nametoindex("en0")) == 0) 
    errorFlag = @"if_nametoindex failure";
  else
  {
    // Get the size of the data available (store in len)
    if (sysctl(mgmtInfoBase, 6, NULL, &length, NULL, 0) < 0) 
      errorFlag = @"sysctl mgmtInfoBase failure";
    else
    {
      // Alloc memory based on above call
      if ((msgBuffer = malloc(length)) == NULL)
        errorFlag = @"buffer allocation failure";
      else
      {
        // Get system information, store in buffer
        if (sysctl(mgmtInfoBase, 6, msgBuffer, &length, NULL, 0) < 0)
          errorFlag = @"sysctl msgBuffer failure";
      }
    }
  }

  // Befor going any further...
  if (errorFlag != NULL)
  {
    NSLog(@"Error: %@", errorFlag);
    return errorFlag;
  }

  // Map msgbuffer to interface message structure
  interfaceMsgStruct = (struct if_msghdr *) msgBuffer;

  // Map to link-level socket structure
  socketStruct = (struct sockaddr_dl *) (interfaceMsgStruct + 1);

  // Copy link layer address data in socket structure to an array
  memcpy(&macAddress, socketStruct->sdl_data + socketStruct->sdl_nlen, 6);

  // Read from char array into a string object, into traditional Mac address format
  NSString *macAddressString = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X", 
                                macAddress[0], macAddress[1], macAddress[2], 
                                macAddress[3], macAddress[4], macAddress[5]];
  NSLog(@"Mac Address: %@", macAddressString);

  // Release the buffer memory
  free(msgBuffer);

  return macAddressString;
}

UITextField 입력 시 화면 위로 스크롤 iPhone

1. Return key 입력

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

if (textField == addressField) {

[portField becomeFirstResponder];

} else if (textField == portField) {

[idField becomeFirstResponder];

} else if (textField == idField) {

[pwField becomeFirstResponder];

} else {

[pwField resignFirstResponder];

        [self loginProcess];

}

    

return YES;

}


2. 화면 위/아래로 스크롤

- (void)textFieldDidBeginEditing:(UITextField *)textField {    

    if (textField == portField || textField == idField || textField == pwField) {

        [UIView beginAnimations:nil context:NULL];

        [UIView setAnimationDelegate:self];

        [UIView setAnimationDuration:0.5];

        [UIView setAnimationBeginsFromCurrentState:YES];

        

        if (textField == pwField) {

            self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y - 200.0), self.view.frame.size.width, self.view.frame.size.height);

        } else {

            self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y - 100.0), self.view.frame.size.width, self.view.frame.size.height);            

        }

        [UIView commitAnimations];

    }

}


- (void)textFieldDidEndEditing:(UITextField *)textField {

    if (textField == portField || textField == idField || textField == pwField) {

        [UIView beginAnimations:nil context:NULL];

        [UIView setAnimationDelegate:self];

        [UIView setAnimationDuration:0.5];

        [UIView setAnimationBeginsFromCurrentState:YES];


        if (textField == pwField) {

            self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y + 200.0), self.view.frame.size.width, self.view.frame.size.height);

        } else {

            self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y + 100.0), self.view.frame.size.width, self.view.frame.size.height);            

        }

        [UIView commitAnimations];

    }

}



NSUserDefaults iPhone


* Set default value
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
[userDefault setObject:nameTextField.text forKey:@"nameKey"];

* Get default value
NSUserDefaults * userDefault = [NSUserDefaults standardUserDefaults];
NSString *defaultString = [userDefault objectForKey:@"nameKey"];
//If nothing loaded (there was nothing saved)
if (defaultString == nil) {
//Set the string to the default
defaultString = @"Enter String";
......
}

//Or if something actually did load
else {
......
}

iPhone Icon Size iPhone


 파일 이름 아이콘 사이즈용도
 Icon.png 57x57 일반적인 아이폰 아이콘
 Icon@2x.png 114x114 고해상도 iPhone4 아이콘
 Icon-72.png 72x72 아이패드 아이콘
 Icon-Small.png 29x29 설정용 아이폰 아이콘 
 Icon-Small@2x.png 58x58 설정 및 검색 결과 고해상도 iPhone4 아이콘
 Icon-Small-50.png 50x50 설정 및 검색 결과 아이패드 아이콘


iPhone : NSString URL 인코딩/디코딩 iPhone

http://theeye.pe.kr/entry/how-to-convert-escaped-string-with-NSString?category=26

    // 오리지널 메시지
   
NSString *original = @"Hello, Nice to meet you\nWelcome to my blog(http://theeye.pe.kr)";
   
   
// URL Encode
   
NSString *escaped = [original stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
   
NSLog(@"escaped string :\n%@", escaped);
   
   
// URL Decode
   
NSString *decoded = [escaped stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
   
NSLog(@"decoded string :\n%@", decoded);

2009-04-03 12:20:58.721 URLEncodeExample[342:20b] escaped string :
Hello,%20Nice%20to%20meet%20you%0AWelcome%20to%20my%20blog(http://theeye.pe.kr)
2009-04-03 12:20:58.723 URLEncodeExample[342:20b] decoded string :
Hello, Nice to meet you
Welcome to my blog(http://theeye.pe.kr)

1 2