随笔 - 35  文章 - 21  trackbacks - 0
<2012年1月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿

随笔分类

随笔档案

文章分类

搜索

  •  

最新评论

阅读排行榜

评论排行榜

1 Launch Keychain Access from your local Mac and from the login keychain, filter by the Certificates category. You will see an expandable option called “Apple Development Push Services”
2 Right click on “Apple Development Push Services” > Export “Apple Development Push Services ID123″. Save this as apns-dev-cert.p12 file somewhere you can access it. There is no need to enter a password.
3 The next command generates the cert in Mac’s Terminal for PEM format (Privacy Enhanced Mail Security Certificate):
openssl pkcs12 -in apns-dev-cert.p12 -out apns-dev-cert.pem -nodes -clcerts
posted @ 2012-05-29 11:07 lincode 阅读(714) | 评论 (0)编辑 收藏

这个 bug 在 xcode 4.3 以下会出现,4.3 以后已经修正了。
解决方法为:找到 target 的图标,更改其 Other Linker Flags 为: -all_load 或 -force_load
-force_load,后跟随一个文件位置,可以更精确地加载所需文件。
 
苹果的解释为 : http://developer.apple.com/library/mac/#qa/qa1490/_index.html

简单点说就是,Objective-C 的动态特性使得需要,为链接器添加一个标签(设置 Other Linker Flags 为 -ObjC)来解决通过 Category 向类添加方法的问题。
但这个标签 -ObjC 在 64 位 和 iOS 中有问题,需要使用 -all_load 或 -force_load。

总结如下:
如果,第三库中没有 category,Other Linker Flags 无需设置
如果,第三方库中有 category,需要设置为 -ObjC
如果,某些 Xcode 版本中,出现问题,修改设置为 -all_load
posted @ 2012-04-23 14:56 lincode 阅读(1796) | 评论 (0)编辑 收藏
获得 Crash Report:
1 itunesConnect 的后台会提供一个 Crash report 表;
2 把一台打开了开发模式的机器接入 Mac,Xcode 的 Organizer 中能查看这台设备的 Crash Report;
3 若使用了 Umeng.com, Bugsense.com 之类的工具。

阅读 Crash Report:
这之前需要一个名为 AppName.app.dSYM 的文件。Xcode 中,Archive 一个项目之后,可以在 Organizer 的 Archives 分页中,找到所有项目的 Archvie 文件。
右键点击一个, Show Package Content,就能看到一个类似 AppName-3-19-12.app.PM.xcarchive  的文件,show in finder 这个文件,就能找到 .dSYM 文件。

在 Ternimal 中执行,若是 来自于 iphone 3G 的机器,就需要使用 armv6 代替 armv7.

 atos -o AppName.app.dSYM/Contents/Resources/DWARF/AppName  -arch armv7 0x0000b82

这样就能看到,地址对应的类,函数,代码行数。这个命令只能解析出客户代码的位置。若是错误堆栈中的系统调用,是无法翻译出来的。
posted @ 2012-03-18 13:56 lincode 阅读(980) | 评论 (0)编辑 收藏
Apple 提供了一个地址方向解析的服务 MKReverseGeocoder,上传一个经纬度,返回一个详细的地理位置信息。但这个服务在中国不太稳定,时常不可用。
Google map 也提供了一个类似的服务,是访问一个 google map 的 api,这里试图封装了 google map 的服务。使使用 apple 和 google 的服务的接口基本一致,替换起来很容易。Google map 的这个服务在中国的状态比 apple 稍微好一些,但也有不稳定的时候。我猜想,apple 也许是使用 google 的服务封装了自己的 MKReverseGeocoder。若是如此,这里的尝试也就没有什么意义了。

DOUHttpRequest 是对 ASIHTTPRequest 的一个简单封装。这些代码可以 继承自 MKReverseGeocoder。这样,使用方法就和 MKReverseGeocoder 一样了。

static NSString* kGeoServerUrl = @"http://maps.google.com/maps/api/geocode/json?latlng=%f,%f&sensor=true&language=en";
static NSString* kLatitudeUserInfoKey = @"latitudeUserInfoKey";
static NSString* kLongitudeUserInfoKey = @"longitudeUserInfoKey";

//
// It's tje solution for replacing MKReverseGeocoder that has problem in China.
//
- (void)startedReverseGeoderWithLatitude:(double)latitude longitude:(double)longitude {
  NSString *url = [NSString stringWithFormat:kGeoServerUrl, latitude, longitude];
  DOUHttpRequest *req = [DOUHttpRequest requestWithURL:[NSURL URLWithString:url] target:self];
  
  NSNumber *lat = [NSNumber numberWithDouble:latitude];
  NSNumber *lon = [NSNumber numberWithDouble:longitude];
  req.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:lat, kLatitudeUserInfoKey, lon, kLongitudeUserInfoKey, nil];
  
  DOUService *service = [DOUService sharedInstance];  
  [service addRequest:req];
}


- (NSDictionary *)addressDictionary:(NSObject *)obj {
  
  NSArray* ary = nil;
  if (IS_INSTANCE_OF(obj, NSDictionary)) {
    NSObject* data = [(NSDictionary*)obj objectForKey:@"results"];
    if (IS_INSTANCE_OF(data, NSArray)) {
      ary = (NSArray*)data;
      NSDictionary *dic = [ary objectAtIndex:0];
      
      NSArray *addressComps = [dic objectForKey:@"address_components"];
      
      //NSString *streetNumber = @"";
      NSString *route = @"";
      NSString *locality = @"";
      NSString *country = @"";
      for (NSDictionary *comp in addressComps) {
        NSArray *types = [comp objectForKey:@"types"];
        NSString *type = [types objectAtIndex:0];
        
//        if ([type isEqualToString:@"street_number"]) {
//          streetNumber = [comp objectForKey:@"long_name"];
//        }
        
        if ([type isEqualToString:@"route"]) {
          route = [comp objectForKey:@"long_name"];
        }
        
        if ([type isEqualToString:@"locality"]) {
          locality = [comp objectForKey:@"long_name"];
        }
        
        if ([type isEqualToString:@"country"]) {
          country = [comp objectForKey:@"long_name"];
        }        
      }
      
      NSDictionary *addressDic = [NSDictionary dictionaryWithObjectsAndKeys:route, kABPersonAddressStreetKey,
                                  locality, kABPersonAddressCityKey,                                        
                                  country, kABPersonAddressCountryKey, nil];
      return addressDic;
    }
  }
  return nil;
}


- (void)requestFinished:(DOUHttpRequest *)req {
  NSError *error = [req error];
  if (!error) {
    DebugLog(@"str:%@", [req responseString]);
    
    NSObject *obj = [[req responseString] JSONValue];
    NSDictionary *addressDic = [self addressDictionary:obj];
    
    CLLocationCoordinate2D coordinate;
    coordinate.latitude = [[req.userInfo objectForKey:kLatitudeUserInfoKey] doubleValue];
    coordinate.longitude = [[req.userInfo objectForKey:kLongitudeUserInfoKey] doubleValue]; 
    MKPlacemark *placemark = [[[MKPlacemark alloc] initWithCoordinate:coordinate 
                                                   addressDictionary:addressDic] autorelease];
    [self reverseGeocoder:nil didFindPlacemark:placemark];
  }
}

- (void)requestFailed:(DOUHttpRequest *)req { 
  [self reverseGeocoder:nil didFailWithError:[req error]];
}


#pragma mark - MKReverseGeocoderDelegate

static NSString * const AppleLanguagesKey = @"AppleLanguages";

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {

  NSArray *array = [[NSUserDefaults standardUserDefaults] objectForKey:AppleLanguagesKey];
  NSString *currentLanguage = [array objectAtIndex:0];
  
  // set current language as english
  [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"zh-Hans", nil] 
                                            forKey:AppleLanguagesKey];
  NSString *local = [placemark.locality lowercaseString];
 
  [AppContext sharedInstance].currentCityUid = local;
  
  // reset current language
  [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:currentLanguage, nil] 
                                            forKey:AppleLanguagesKey];
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {
  TraceLog(@"reverseGeocoder :%@", [error localizedDescription]);  
}
posted @ 2012-01-12 21:27 lincode 阅读(1305) | 评论 (0)编辑 收藏