我有兩台Mac電腦,一台Snow leopard已經裝了xcode4
另外一台Lion的因為工作關係,還不敢貿然亂升級
眼看iOS 5.1都在beta了,想說來升級一下xcode4
結果裝完要找project build出來的ipa
路徑是設定在/User/(name)/Library(資源庫)/Developer/Xcode/Archives
但是在我的Lion上面遍尋不著阿@@
搞了老半天原來是被隱藏起來了
Apple Support Communities有滿完整的討論
#import <sys sysctl.h=""> #import <netinet in.h=""> #import <arpa inet.h=""> #import "route.h" /*the very same from google-code*/ #define CTL_NET 4 /* network, see socket.h */ #define ROUNDUP(a) \ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) - (NSString *)getGatewayIPAddress { NSString *address = @"error"; /* net.route.0.inet.flags.gateway */ int mib[] = {CTL_NET, PF_ROUTE, 0, AF_INET, NET_RT_FLAGS, RTF_GATEWAY}; size_t l; char * buf, * p; struct rt_msghdr * rt; struct sockaddr * sa; struct sockaddr * sa_tab[RTAX_MAX]; int i; int r = -1; if(sysctl(mib, sizeof(mib)/sizeof(int), 0, &l, 0, 0) < 0) { address = @"192.168.0.1"; //return -1; } if(l>0) { buf = malloc(l); if(sysctl(mib, sizeof(mib)/sizeof(int), buf, &l, 0, 0) < 0) { address = @"192.168.0.1"; //return -1; } for(p=buf; p<buf+l; p+="rt-">rtm_msglen) { rt = (struct rt_msghdr *)p; sa = (struct sockaddr *)(rt + 1); for(i=0; i<rtax_max; i++)="" if(rt-="" {="">rtm_addrs & (1 << i)) { sa_tab[i] = sa; sa = (struct sockaddr *)((char *)sa + ROUNDUP(sa->sa_len)); } else { sa_tab[i] = NULL; } } if( ((rt->rtm_addrs & (RTA_DST|RTA_GATEWAY)) == (RTA_DST|RTA_GATEWAY)) && sa_tab[RTAX_DST]->sa_family == AF_INET && sa_tab[RTAX_GATEWAY]->sa_family == AF_INET) { unsigned char octet[4] = {0,0,0,0}; int i; for (i=0; i<4; i++){ octet[i] = ( ((struct sockaddr_in *)(sa_tab[RTAX_GATEWAY]))->sin_addr.s_addr >> (i*8) ) & 0xFF; } if(((struct sockaddr_in *)sa_tab[RTAX_DST])->sin_addr.s_addr == 0) { //if(octet[0] == 192 && octet[1] == 168){ in_addr_t addr = ((struct sockaddr_in *)(sa_tab[RTAX_GATEWAY]))->sin_addr.s_addr; r = 0; address = [NSString stringWithFormat:@"%s", inet_ntoa(*((struct in_addr*)&addr))]; //} NSLog(@"\naddress%@",address); break; } } } free(buf); } return address; }
[request setAllHTTPHeaderFields: [NSDictionary dictionaryWithObjectsAndKeys: @"iPhone", @"User-Agent", @"close", @"Connection", @"gzip", @"Accept-Encoding", @"*/*", @"Accept", nil]];2. 如果改個其中一個
[request setValue:@"aValue" forHTTPHeaderField:@"field"];只是有兩點要比較注意的:
1 2 | // add native edit button on navigation bar
self.navigationItem.rightBarButtonItem = self.editButtonItem;
|
1 2 3 4 | // If we're in editing mode, we add a placeholder row for creating new items. if (self.editing) { count++; } |
1 2 3 4 5 6 7 | if (indexPath.row == [myArray count]) { // assign the content of last cell in editing mode [cell.textLabel setText:@"Add new data"]; cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator; } else { // assign other cell data } |
1 2 3 4 5 | if (indexPath.row == [myArray count]) { [myTable deselectRowAtIndexPath:indexPath animated:YES]; if (self.editing) { // Called after selection. In editing mode, this will navigate to a new view controller. } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | - (void)setEditing:(BOOL)editing animated:(BOOL)animated { [super setEditing:editing animated:animated]; [myTable setEditing:editing animated:animated]; [self.navigationItem setHidesBackButton:editing animated:YES]; [myTable beginUpdates]; NSUInteger wc = [myArray count]; NSArray *myInsertIndexPath = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:wc inSection:0]]; if (editing) { [myTable insertRowsAtIndexPaths:myInsertIndexPath withRowAnimation:UITableViewRowAnimationTop]; } else { [myTable deleteRowsAtIndexPaths:myInsertIndexPath withRowAnimation:UITableViewRowAnimationTop]; } [myTable endUpdates]; } |
1 2 3 4 5 6 7 8 | - (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { // The editing style for a row is the kind of button displayed to the left of the cell when in editing mode. if (indexPath.row == [myArray count]) { return UITableViewCellEditingStyleInsert; } else { return UITableViewCellEditingStyleDelete; } } |
1 2 3 4 5 6 | - (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Remove the corresponding object and delete the appropriate table view cell. [myArray removeObjectAtIndex:indexPath.row]; [myTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop]; } |
1 2 3 4 5 6 7 8 9 | - (void)addCellDone { // update array NSString *v =[NSString stringWithFormat:@"123"]; [self.weightArray addObject:v]; // reload table [myTable reloadData]; //remove modal view [self dismissModalViewControllerAnimated:YES]; } |
1 | [self.imageView addGestureRecognizer:tapGestureRecognize]; |
1 | - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | //.h @interface showDigitNumberController : UIViewController //.m // Create the Swipe Gesture Recognizer UISwipeGestureRecognizer *SwipeRecognizer = nil; SwipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(mySwipeGestureRecognizer:)]; [SwipeRecognizer setDirection:(UISwipeGestureRecognizerDirectionUp)]; [self.view addGestureRecognizer:SwipeRecognizer]; // assign the delegate here SwipeRecognizer.delegate = self; [SwipeRecognizer release]; SwipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(mySwipeGestureRecognizer:)]; [SwipeRecognizer setDirection:(UISwipeGestureRecognizerDirectionDown)]; [self.view addGestureRecognizer:SwipeRecognizer]; [SwipeRecognizer release]; // Create Single Tap Gesture Recognizer UITapGestureRecognizer *tapGestureRecognize = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myTapGestureRecognizer:)]; tapGestureRecognize.numberOfTapsRequired = 1; [self.view addGestureRecognizer:tapGestureRecognize]; [tapGestureRecognize release]; - (void)mySwipeGestureRecognizer:(UISwipeGestureRecognizer *)Sender { switch(Sender.direction){ case UISwipeGestureRecognizerDirectionUp: // do something break; case UISwipeGestureRecognizerDirectionDown: // do something break; case UISwipeGestureRecognizerDirectionLeft: // do something break; case UISwipeGestureRecognizerDirectionRight: // do something break; default: break; } } - (void)myTapGestureRecognizer:(UITapGestureRecognizer *)Sender{ // do something } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { } |