﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-不过而而</title><link>http://www.blogjava.net/lincode/</link><description /><language>zh-cn</language><lastBuildDate>Tue, 14 Apr 2026 14:18:57 GMT</lastBuildDate><pubDate>Tue, 14 Apr 2026 14:18:57 GMT</pubDate><ttl>60</ttl><item><title>[iOS] 生成 Push Notification pem 文件</title><link>http://www.blogjava.net/lincode/archive/2012/05/29/379418.html</link><dc:creator>lincode</dc:creator><author>lincode</author><pubDate>Tue, 29 May 2012 03:07:00 GMT</pubDate><guid>http://www.blogjava.net/lincode/archive/2012/05/29/379418.html</guid><wfw:comment>http://www.blogjava.net/lincode/comments/379418.html</wfw:comment><comments>http://www.blogjava.net/lincode/archive/2012/05/29/379418.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lincode/comments/commentRss/379418.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lincode/services/trackbacks/379418.html</trackback:ping><description><![CDATA[<div>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 &#8220;Apple Development Push Services&#8221;<br /></div><div>2 Right click on &#8220;Apple Development Push Services&#8221; &gt; Export &#8220;Apple Development Push Services ID123&#8243;. Save this as apns-dev-cert.p12 file somewhere you can access it. There is no need to enter a password.</div><div></div><div>3 The next command generates the cert in Mac&#8217;s Terminal for PEM format (Privacy Enhanced Mail Security Certificate):</div><div></div><div>openssl pkcs12 -in apns-dev-cert.p12 -out apns-dev-cert.pem -nodes -clcerts</div><img src ="http://www.blogjava.net/lincode/aggbug/379418.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lincode/" target="_blank">lincode</a> 2012-05-29 11:07 <a href="http://www.blogjava.net/lincode/archive/2012/05/29/379418.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[iOS] 引用外部静态库时，目录方法无法加载问题</title><link>http://www.blogjava.net/lincode/archive/2012/04/23/376373.html</link><dc:creator>lincode</dc:creator><author>lincode</author><pubDate>Mon, 23 Apr 2012 06:56:00 GMT</pubDate><guid>http://www.blogjava.net/lincode/archive/2012/04/23/376373.html</guid><wfw:comment>http://www.blogjava.net/lincode/comments/376373.html</wfw:comment><comments>http://www.blogjava.net/lincode/archive/2012/04/23/376373.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lincode/comments/commentRss/376373.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lincode/services/trackbacks/376373.html</trackback:ping><description><![CDATA[<br />这个 bug 在 xcode 4.3 以下会出现，4.3 以后已经修正了。<br />解决方法为：找到 target 的图标，更改其 Other Linker Flags 为： -all_load 或 -force_load<br />-force_load，后跟随一个文件位置，可以更精确地加载所需文件。<br />&nbsp;<br />苹果的解释为 ： <a href="http://developer.apple.com/library/mac/#qa/qa1490/_index.html">http://developer.apple.com/library/mac/#qa/qa1490/_index.html</a><br /><br />简单点说就是，Objective-C 的动态特性使得需要，为链接器添加一个标签（设置 Other Linker Flags 为 -ObjC）来解决通过 Category 向类添加方法的问题。<br />但这个标签 －ObjC 在 64 位 和 iOS 中有问题，需要使用 -all_load 或 -force_load。<br /><br />总结如下：<br />如果，第三库中没有 category，Other Linker Flags 无需设置<br />如果，第三方库中有 category，需要设置为 -ObjC<br />如果，某些 Xcode 版本中，出现问题，修改设置为 -all_load<img src ="http://www.blogjava.net/lincode/aggbug/376373.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lincode/" target="_blank">lincode</a> 2012-04-23 14:56 <a href="http://www.blogjava.net/lincode/archive/2012/04/23/376373.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[iOS] 阅读 Crash Report </title><link>http://www.blogjava.net/lincode/archive/2012/03/18/372131.html</link><dc:creator>lincode</dc:creator><author>lincode</author><pubDate>Sun, 18 Mar 2012 05:56:00 GMT</pubDate><guid>http://www.blogjava.net/lincode/archive/2012/03/18/372131.html</guid><wfw:comment>http://www.blogjava.net/lincode/comments/372131.html</wfw:comment><comments>http://www.blogjava.net/lincode/archive/2012/03/18/372131.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lincode/comments/commentRss/372131.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lincode/services/trackbacks/372131.html</trackback:ping><description><![CDATA[<strong>获得 Crash Report：</strong><br />1 itunesConnect 的后台会提供一个 Crash report 表；<br />2 把一台打开了开发模式的机器接入 Mac，Xcode 的 Organizer 中能查看这台设备的 Crash Report；<br />3 若使用了 Umeng.com, Bugsense.com 之类的工具。<br /><br /><strong>阅读 Crash Report:</strong><br />这之前需要一个名为 AppName.app.dSYM 的文件。Xcode 中，Archive 一个项目之后，可以在 Organizer 的 Archives 分页中，找到所有项目的 Archvie 文件。<br />右键点击一个， Show Package Content，就能看到一个类似 AppName－3－19－12.app.PM.xcarchive&nbsp; 的文件，show in finder 这个文件，就能找到 .dSYM 文件。<br /><br />在 Ternimal 中执行，若是 来自于 iphone 3G 的机器，就需要使用 armv6 代替 armv7.<br /><div><br />&nbsp;atos -o AppName.app.dSYM/Contents/Resources/DWARF/AppName &nbsp;-arch armv7 0x0000b82<br /><br />这样就能看到，地址对应的类，函数，代码行数。这个命令只能解析出客户代码的位置。若是错误堆栈中的系统调用，是无法翻译出来的。</div><img src ="http://www.blogjava.net/lincode/aggbug/372131.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lincode/" target="_blank">lincode</a> 2012-03-18 13:56 <a href="http://www.blogjava.net/lincode/archive/2012/03/18/372131.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[iOS] 地址反向解析</title><link>http://www.blogjava.net/lincode/archive/2012/01/12/368424.html</link><dc:creator>lincode</dc:creator><author>lincode</author><pubDate>Thu, 12 Jan 2012 13:27:00 GMT</pubDate><guid>http://www.blogjava.net/lincode/archive/2012/01/12/368424.html</guid><wfw:comment>http://www.blogjava.net/lincode/comments/368424.html</wfw:comment><comments>http://www.blogjava.net/lincode/archive/2012/01/12/368424.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lincode/comments/commentRss/368424.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lincode/services/trackbacks/368424.html</trackback:ping><description><![CDATA[Apple 提供了一个地址方向解析的服务&nbsp;MKReverseGeocoder，上传一个经纬度，返回一个详细的地理位置信息。但这个服务在中国不太稳定，时常不可用。<br />Google map 也提供了一个类似的服务，是访问一个 google map 的 api，这里试图封装了 google map 的服务。使使用 apple 和 google 的服务的接口基本一致，替换起来很容易。Google map 的这个服务在中国的状态比 apple 稍微好一些，但也有不稳定的时候。我猜想，apple 也许是使用 google 的服务封装了自己的&nbsp;MKReverseGeocoder。若是如此，这里的尝试也就没有什么意义了。<br /><br />DOUHttpRequest 是对 ASIHTTPRequest 的一个简单封装。这些代码可以 继承自&nbsp;MKReverseGeocoder。这样，使用方法就和 MKReverseGeocoder 一样了。<br /><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">static</span>&nbsp;NSString*&nbsp;kGeoServerUrl&nbsp;=&nbsp;@"http://maps.google.com/maps/api/geocode/json?latlng=%f,%f&amp;sensor=true&amp;language=en";<br /><span style="color: #0000FF; ">static</span>&nbsp;NSString*&nbsp;kLatitudeUserInfoKey&nbsp;=&nbsp;@"latitudeUserInfoKey";<br /><span style="color: #0000FF; ">static</span>&nbsp;NSString*&nbsp;kLongitudeUserInfoKey&nbsp;=&nbsp;@"longitudeUserInfoKey";<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; "><br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;It's&nbsp;tje&nbsp;solution&nbsp;for&nbsp;replacing&nbsp;MKReverseGeocoder&nbsp;that&nbsp;has&nbsp;problem&nbsp;in&nbsp;China.<br /></span><span style="color: #008000; ">//<br /></span>-&nbsp;(<span style="color: #0000FF; ">void</span>)startedReverseGeoderWithLatitude:(<span style="color: #0000FF; ">double</span>)latitude&nbsp;longitude:(<span style="color: #0000FF; ">double</span>)longitude&nbsp;{<br />&nbsp;&nbsp;NSString&nbsp;*url&nbsp;=&nbsp;[NSString&nbsp;stringWithFormat:kGeoServerUrl,&nbsp;latitude,&nbsp;longitude];<br />&nbsp;&nbsp;DOUHttpRequest&nbsp;*req&nbsp;=&nbsp;[DOUHttpRequest&nbsp;requestWithURL:[NSURL&nbsp;URLWithString:url]&nbsp;target:self];<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;NSNumber&nbsp;*lat&nbsp;=&nbsp;[NSNumber&nbsp;numberWithDouble:latitude];<br />&nbsp;&nbsp;NSNumber&nbsp;*lon&nbsp;=&nbsp;[NSNumber&nbsp;numberWithDouble:longitude];<br />&nbsp;&nbsp;req.userInfo&nbsp;=&nbsp;[NSDictionary&nbsp;dictionaryWithObjectsAndKeys:lat,&nbsp;kLatitudeUserInfoKey,&nbsp;lon,&nbsp;kLongitudeUserInfoKey,&nbsp;nil];<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;DOUService&nbsp;*service&nbsp;=&nbsp;[DOUService&nbsp;sharedInstance];&nbsp;&nbsp;<br />&nbsp;&nbsp;[service&nbsp;addRequest:req];<br />}<br /><br /><br />-&nbsp;(NSDictionary&nbsp;*)addressDictionary:(NSObject&nbsp;*)obj&nbsp;{<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;NSArray*&nbsp;ary&nbsp;=&nbsp;nil;<br />&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;(IS_INSTANCE_OF(obj,&nbsp;NSDictionary))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;NSObject*&nbsp;data&nbsp;=&nbsp;[(NSDictionary*)obj&nbsp;objectForKey:@"results"];<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;(IS_INSTANCE_OF(data,&nbsp;NSArray))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ary&nbsp;=&nbsp;(NSArray*)data;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSDictionary&nbsp;*dic&nbsp;=&nbsp;[ary&nbsp;objectAtIndex:0];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSArray&nbsp;*addressComps&nbsp;=&nbsp;[dic&nbsp;objectForKey:@"address_components"];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">NSString&nbsp;*streetNumber&nbsp;=&nbsp;@"";</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSString&nbsp;*route&nbsp;=&nbsp;@"";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSString&nbsp;*locality&nbsp;=&nbsp;@"";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSString&nbsp;*country&nbsp;=&nbsp;@"";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">for</span>&nbsp;(NSDictionary&nbsp;*comp&nbsp;in&nbsp;addressComps)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSArray&nbsp;*types&nbsp;=&nbsp;[comp&nbsp;objectForKey:@"types"];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSString&nbsp;*type&nbsp;=&nbsp;[types&nbsp;objectAtIndex:0];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;([type&nbsp;isEqualToString:@"street_number"])&nbsp;{<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;streetNumber&nbsp;=&nbsp;[comp&nbsp;objectForKey:@"long_name"];<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;([type&nbsp;isEqualToString:@"route"])&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;route&nbsp;=&nbsp;[comp&nbsp;objectForKey:@"long_name"];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;([type&nbsp;isEqualToString:@"locality"])&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;locality&nbsp;=&nbsp;[comp&nbsp;objectForKey:@"long_name"];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;([type&nbsp;isEqualToString:@"country"])&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;country&nbsp;=&nbsp;[comp&nbsp;objectForKey:@"long_name"];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSDictionary&nbsp;*addressDic&nbsp;=&nbsp;[NSDictionary&nbsp;dictionaryWithObjectsAndKeys:route,&nbsp;kABPersonAddressStreetKey,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;locality,&nbsp;kABPersonAddressCityKey,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;country,&nbsp;kABPersonAddressCountryKey,&nbsp;nil];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;addressDic;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;nil;<br />}<br /><br /><br />-&nbsp;(<span style="color: #0000FF; ">void</span>)requestFinished:(DOUHttpRequest&nbsp;*)req&nbsp;{<br />&nbsp;&nbsp;NSError&nbsp;*error&nbsp;=&nbsp;[req&nbsp;error];<br />&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;(!error)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;DebugLog(@"str:%@",&nbsp;[req&nbsp;responseString]);<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;NSObject&nbsp;*obj&nbsp;=&nbsp;[[req&nbsp;responseString]&nbsp;JSONValue];<br />&nbsp;&nbsp;&nbsp;&nbsp;NSDictionary&nbsp;*addressDic&nbsp;=&nbsp;[self&nbsp;addressDictionary:obj];<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;CLLocationCoordinate2D&nbsp;coordinate;<br />&nbsp;&nbsp;&nbsp;&nbsp;coordinate.latitude&nbsp;=&nbsp;[[req.userInfo&nbsp;objectForKey:kLatitudeUserInfoKey]&nbsp;doubleValue];<br />&nbsp;&nbsp;&nbsp;&nbsp;coordinate.longitude&nbsp;=&nbsp;[[req.userInfo&nbsp;objectForKey:kLongitudeUserInfoKey]&nbsp;doubleValue];&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;MKPlacemark&nbsp;*placemark&nbsp;=&nbsp;[[[MKPlacemark&nbsp;alloc]&nbsp;initWithCoordinate:coordinate&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addressDictionary:addressDic]&nbsp;autorelease];<br />&nbsp;&nbsp;&nbsp;&nbsp;[self&nbsp;reverseGeocoder:nil&nbsp;didFindPlacemark:placemark];<br />&nbsp;&nbsp;}<br />}<br /><br />-&nbsp;(<span style="color: #0000FF; ">void</span>)requestFailed:(DOUHttpRequest&nbsp;*)req&nbsp;{&nbsp;<br />&nbsp;&nbsp;[self&nbsp;reverseGeocoder:nil&nbsp;didFailWithError:[req&nbsp;error]];<br />}<br /><br /><br />#pragma&nbsp;mark&nbsp;-&nbsp;MKReverseGeocoderDelegate<br /><br /><span style="color: #0000FF; ">static</span>&nbsp;NSString&nbsp;*&nbsp;<span style="color: #0000FF; ">const</span>&nbsp;AppleLanguagesKey&nbsp;=&nbsp;@"AppleLanguages";<br /><br />-&nbsp;(<span style="color: #0000FF; ">void</span>)reverseGeocoder:(MKReverseGeocoder&nbsp;*)geocoder&nbsp;didFindPlacemark:(MKPlacemark&nbsp;*)placemark&nbsp;{<br /><br />&nbsp;&nbsp;NSArray&nbsp;*array&nbsp;=&nbsp;[[NSUserDefaults&nbsp;standardUserDefaults]&nbsp;objectForKey:AppleLanguagesKey];<br />&nbsp;&nbsp;NSString&nbsp;*currentLanguage&nbsp;=&nbsp;[array&nbsp;objectAtIndex:0];<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;set&nbsp;current&nbsp;language&nbsp;as&nbsp;english</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;[[NSUserDefaults&nbsp;standardUserDefaults]&nbsp;setObject:[NSArray&nbsp;arrayWithObjects:@"zh-Hans",&nbsp;nil]&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;forKey:AppleLanguagesKey];<br />&nbsp;&nbsp;NSString&nbsp;*local&nbsp;=&nbsp;[placemark.locality&nbsp;lowercaseString];<br />&nbsp;<br />&nbsp;&nbsp;[AppContext&nbsp;sharedInstance].currentCityUid&nbsp;=&nbsp;local;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;reset&nbsp;current&nbsp;language</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;[[NSUserDefaults&nbsp;standardUserDefaults]&nbsp;setObject:[NSArray&nbsp;arrayWithObjects:currentLanguage,&nbsp;nil]&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;forKey:AppleLanguagesKey];<br />}<br /><br />-&nbsp;(<span style="color: #0000FF; ">void</span>)reverseGeocoder:(MKReverseGeocoder&nbsp;*)geocoder&nbsp;didFailWithError:(NSError&nbsp;*)error&nbsp;{<br />&nbsp;&nbsp;TraceLog(@"reverseGeocoder&nbsp;:%@",&nbsp;[error&nbsp;localizedDescription]);&nbsp;&nbsp;<br />}</div><img src ="http://www.blogjava.net/lincode/aggbug/368424.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lincode/" target="_blank">lincode</a> 2012-01-12 21:27 <a href="http://www.blogjava.net/lincode/archive/2012/01/12/368424.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OAuth 基本概念</title><link>http://www.blogjava.net/lincode/archive/2011/10/27/362182.html</link><dc:creator>lincode</dc:creator><author>lincode</author><pubDate>Thu, 27 Oct 2011 10:15:00 GMT</pubDate><guid>http://www.blogjava.net/lincode/archive/2011/10/27/362182.html</guid><wfw:comment>http://www.blogjava.net/lincode/comments/362182.html</wfw:comment><comments>http://www.blogjava.net/lincode/archive/2011/10/27/362182.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lincode/comments/commentRss/362182.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lincode/services/trackbacks/362182.html</trackback:ping><description><![CDATA[<font class="Apple-style-span" size="5"><strong><br />定义</strong></font><span class="Apple-style-span" style="font-family: sans-serif; font-size: 15px; line-height: 22px; background-color: #ffffff; "><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; "><strong style="font-size: 14pt; ">OAuth</strong>（开放授权）是一个<a href="http://zh.wikipedia.org/w/index.php?title=%E5%BC%80%E6%94%BE%E6%A0%87%E5%87%86&amp;action=edit&amp;redlink=1" class="new" title="开放标准" style="text-decoration: none; color: #ba0000; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">开放标准</a>，允许用户让第三方应用访问该用户在某一网站上存储的私密的资源（如照片，视频，联系人列表），而无需将用户名和密码提供给第三方应用。</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">OAuth允许用户提供一个令牌，而不是用户名和密码来访问他们存放在特定服务提供者的数据。每一个令牌授权一个特定的网站（例如，视频编辑网站)在特定的时段（例如，接下来的2小时内）内访问特定的资源（例如仅仅是某一相册中的视频）。这样，OAuth允许用户授权第三方网站访问他们存储在另外的服务提供者上的信息，而不需要分享他们的访问许可或他们数据的所有内容。</p></span><strong style="font-size: 18pt; "><br /><br />认证和授权过程</strong><br /><span class="Apple-style-span" style="font-family: sans-serif; font-size: 15px; line-height: 22px; background-color: #ffffff; "><br />在认证和授权的过程中涉及的三方包括：</span><span class="Apple-style-span" style="font-family: sans-serif; font-size: 15px; line-height: 22px; background-color: #ffffff; "><ul style="line-height: 1.5em; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAANCAMAAABW4lS6AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRFAFKM////QIUK9QAAAAJ0Uk5T/wDltzBKAAAAGklEQVR42mJgBAEGokgGBjBGBxBxsBqAAAMACHwALd5r8ygAAAAASUVORK5CYII=); "><li style="margin-bottom: 0.1em; "><strong>服务提供方</strong>，用户使用服务提供方来存储受保护的资源，如照片，视频，联系人列表。</li><li style="margin-bottom: 0.1em; "><strong>用户</strong>，存放在服务提供方的受保护的资源的拥有者。</li><li style="margin-bottom: 0.1em; "><strong>客户端</strong>，要访问服务提供方资源的第三方应用，通常是网站，如提供照片打印服务的网站。在认证过程之前，客户端要向服务提供者申请客户端标识。</li></ul><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">使用OAuth进行认证和授权的过程如下所示:</p><ol style="line-height: 1.5em; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 3.2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: none; "><li style="margin-bottom: 0.1em; "><strong>用户</strong>访问<strong>客户端</strong>的网站，想操作用户存放在<strong>服务提供方</strong>的资源。</li><li style="margin-bottom: 0.1em; "><strong>客户端</strong>向<strong>服务提供方</strong>请求一个临时令牌。</li><li style="margin-bottom: 0.1em; "><strong>服务提供方</strong>验证<strong>客户端</strong>的身份后，授予一个临时令牌。</li><li style="margin-bottom: 0.1em; "><strong>客户端</strong>获得临时令牌后，将用户引导至<strong>服务提供方</strong>的授权页面请求用户授权。在这个过程中将临时令牌和客户端的<a href="http://zh.wikipedia.org/wiki/%E5%9B%9E%E8%B0%83%E5%87%BD%E6%95%B0" title="回调函数" style="text-decoration: none; color: #0645ad; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">回调</a>连接发送给<strong>服务提供方</strong>。</li><li style="margin-bottom: 0.1em; "><strong>用户</strong>在<strong>服务提供方</strong>的网页上输入用户名和密码，然后授权该<strong>客户端</strong>访问所请求的资源。</li><li style="margin-bottom: 0.1em; ">授权成功后，<strong>服务提供方</strong>引导<strong>用户</strong>返回<strong>客户端</strong>的网页。</li><li style="margin-bottom: 0.1em; "><strong>客户端</strong>根据临时令牌从<strong>服务提供方</strong>那里获取访问令牌。</li><li style="margin-bottom: 0.1em; "><strong>服务提供方</strong>根据临时令牌和<strong>用户</strong>的授权情况授予<strong>客户端</strong>访问令牌。</li><li style="margin-bottom: 0.1em; "><strong>客户端</strong>使用获取的访问令牌访问存放在<strong>服务提供方</strong>上的受保护的资源。</li></ol></span><br /><div><strong style="font-size: 18pt; "><br />OAuth 2.0</strong></div><br /><span class="Apple-style-span" style="font-family: sans-serif; font-size: 15px; line-height: 22px; background-color: #ffffff; "><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">OAuth 2.0是OAuth协议的下一版本，但不向后兼容OAuth 1.0。 OAuth 2.0关注客户端开发者的简易性，同时为Web应用，桌面应用和手机，和起居室设备提供专门的认证流程。规范还在IETF OAuth工作组的开发中&nbsp;，按照<a href="http://zh.wikipedia.org/w/index.php?title=Eran_Hammer-Lahav&amp;action=edit&amp;redlink=1" class="new" title="Eran Hammer-Lahav" style="text-decoration: none; color: #ba0000; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">Eran Hammer-Lahav</a>的说法，OAuth将于2010年末完成。</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; "><font class="Apple-style-span" color="#0645ad"><span class="Apple-style-span" style="background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; color: #000000; ">Facebook</span></font>的新的Graph API只支持OAuth 2.0，Google在<font class="Apple-style-span" color="#0645ad"><span class="Apple-style-span" style="background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; color: #000000; ">2011年3月</span></font>亦宣佈Google API對OAuth 2.0的支援。</p></span><img src ="http://www.blogjava.net/lincode/aggbug/362182.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lincode/" target="_blank">lincode</a> 2011-10-27 18:15 <a href="http://www.blogjava.net/lincode/archive/2011/10/27/362182.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>［转］RESTful 理解</title><link>http://www.blogjava.net/lincode/archive/2011/10/27/362180.html</link><dc:creator>lincode</dc:creator><author>lincode</author><pubDate>Thu, 27 Oct 2011 10:02:00 GMT</pubDate><guid>http://www.blogjava.net/lincode/archive/2011/10/27/362180.html</guid><wfw:comment>http://www.blogjava.net/lincode/comments/362180.html</wfw:comment><comments>http://www.blogjava.net/lincode/archive/2011/10/27/362180.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lincode/comments/commentRss/362180.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lincode/services/trackbacks/362180.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="color: #111111; font-family: Georgia, serif; font-size: 10px; line-height: 18px; word-spacing: 2px; background-color: #f5f5d5; "><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; "><strong style="font-weight: 800; ">名称</strong></p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">REST，即Representational State Transfer的缩写。我对这个词组的翻译是"表现层状态转化"。</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">如果一个架构符合REST原则，就称它为RESTful架构。</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; "><strong style="font-weight: 800; ">要理解RESTful架构，最好的方法就是去理解Representational State Transfer这个词组到底是什么意思，它的每一个词代表了什么涵义。</strong>如果你把这个名称搞懂了，也就不难体会REST是一种什么样的设计。</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; "><strong style="font-weight: 800; ">资源（Resources）</strong></p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">REST的名称"表现层状态转化"中，省略了主语。"表现层"其实指的是"资源"（Resources）的"表现层"。</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; "><strong style="font-weight: 800; ">所谓"资源"，就是网络上的一个实体，或者说是网络上的一个具体信息。</strong>它可以是一段文本、一张图片、一首歌曲、一种服务，总之就是一个具体的实在。你可以用一个URI（统一资源定位符）指向它，每种资源对应一个特定的URI。要获取这个资源，访问它的URI就可以，因此URI就成了每一个资源的地址或独一无二的识别符。</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">所谓"上网"，就是与互联网上一系列的"资源"互动，调用它的URI。</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; "><strong style="font-weight: 800; ">表现层（Representation）</strong></p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">"资源"是一种信息实体，它可以有多种外在表现形式。<strong style="font-weight: 800; ">我们把"资源"具体呈现出来的形式，叫做它的"表现层"（Representation）。</strong></p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">比如，文本可以用txt格式表现，也可以用HTML格式、XML格式、JSON格式表现，甚至可以采用二进制格式；图片可以用JPG格式表现，也可以用PNG格式表现。</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">URI只代表资源的实体，不代表它的形式。严格地说，有些网址最后的".html"后缀名是不必要的，因为这个后缀名表示格式，属于"表现层"范畴，而URI应该只代表"资源"的位置。它的具体表现形式，应该在HTTP请求的头信息中用Accept和Content-Type字段指定，这两个字段才是对"表现层"的描述。</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; "><strong style="font-weight: 800; ">状态转化（State Transfer）</strong></p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">访问一个网站，就代表了客户端和服务器的一个互动过程。在这个过程中，势必涉及到数据和状态的变化。</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">互联网通信协议HTTP协议，是一个无状态协议。这意味着，所有的状态都保存在服务器端。因此，<strong style="font-weight: 800; ">如果客户端想要操作服务器，必须通过某种手段，让服务器端发生"状态转化"（State Transfer）。而这种转化是建立在表现层之上的，所以就是"表现层状态转化"。</strong></p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">客户端用到的手段，只能是HTTP协议。具体来说，就是HTTP协议里面，四个表示操作方式的动词：GET、POST、PUT、DELETE。它们分别对应四种基本操作：<strong style="font-weight: 800; ">GET用来获取资源，POST用来新建资源（也可以用于更新资源），PUT用来更新资源，DELETE用来删除资源。</strong></p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; "><strong style="font-weight: 800; ">综述</strong></p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">综合上面的解释，我们总结一下什么是RESTful架构：</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">　　（1）每一个URI代表一种资源；</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">　　（2）客户端和服务器之间，传递这种资源的某种表现层；</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">　　（3）客户端通过四个HTTP动词，对服务器端资源进行操作，实现"表现层状态转化"。</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; "><strong style="font-weight: 800; ">误区</strong></p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">RESTful架构有一些典型的设计误区。</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; "><strong style="font-weight: 800; ">最常见的一种设计错误，就是URI包含动词。</strong>因为"资源"表示一种实体，所以应该是名词，URI不应该有动词，动词应该放在HTTP协议中。</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">举例来说，某个URI是/posts/show/1，其中show是动词，这个URI就设计错了，正确的写法应该是/posts/1，然后用GET方法表示show。</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">如果某些动作是HTTP动词表示不了的，你就应该把动作做成一种资源。比如网上汇款，从账户1向账户2汇款500元，错误的URI是：</p><blockquote style="margin-top: 2em; margin-right: 2em; margin-bottom: 2em; margin-left: 2em; padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; background-color: #e0dfcc; border-top-left-radius: 20px 20px; border-top-right-radius: 20px 20px; border-bottom-right-radius: 20px 20px; border-bottom-left-radius: 20px 20px; "><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">　　POST /accounts/1/transfer/500/to/2</p></blockquote><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">正确的写法是把动词transfer改成名词transaction，资源不能是动词，但是可以是一种服务：</p><blockquote style="margin-top: 2em; margin-right: 2em; margin-bottom: 2em; margin-left: 2em; padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; background-color: #e0dfcc; border-top-left-radius: 20px 20px; border-top-right-radius: 20px 20px; border-bottom-right-radius: 20px 20px; border-bottom-left-radius: 20px 20px; "><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">　　POST /transaction HTTP/1.1<br />　　Host: 127.0.0.1<br />　　<br />　　from=1&amp;to=2&amp;amount=500.00</p></blockquote><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; "><strong style="font-weight: 800; ">另一个设计误区，就是在URI中加入版本号</strong>：</p><blockquote style="margin-top: 2em; margin-right: 2em; margin-bottom: 2em; margin-left: 2em; padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; background-color: #e0dfcc; border-top-left-radius: 20px 20px; border-top-right-radius: 20px 20px; border-bottom-right-radius: 20px 20px; border-bottom-left-radius: 20px 20px; "><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">　　http://www.example.com/app/1.0/foo</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">　　http://www.example.com/app/1.1/foo</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">　　http://www.example.com/app/2.0/foo</p></blockquote><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">因为不同的版本，可以理解成同一种资源的不同表现形式，所以应该采用同一个URI。版本号可以在HTTP请求头信息的Accept字段中进行区分（参见<a href="http://www.informit.com/articles/article.aspx?p=1566460" target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: underline; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #223472; ">Versioning REST Services</a>）：</p><blockquote style="margin-top: 2em; margin-right: 2em; margin-bottom: 2em; margin-left: 2em; padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; background-color: #e0dfcc; border-top-left-radius: 20px 20px; border-top-right-radius: 20px 20px; border-bottom-right-radius: 20px 20px; border-bottom-left-radius: 20px 20px; "><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">　　Accept: vnd.example-com.foo+json; version=1.0</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">　　Accept: vnd.example-com.foo+json; version=1.1</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; text-align: left; text-decoration: none; font-style: normal; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; color: #111111; font-size: 1.6em; line-height: 28px; ">　　Accept: vnd.example-com.foo+json; version=2.0</p></blockquote></span><br /><strong>原帖：http://www.ruanyifeng.com/blog/2011/09/restful.html</strong><img src ="http://www.blogjava.net/lincode/aggbug/362180.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lincode/" target="_blank">lincode</a> 2011-10-27 18:02 <a href="http://www.blogjava.net/lincode/archive/2011/10/27/362180.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[android] PhoneGap 在 android 下的实现原理</title><link>http://www.blogjava.net/lincode/archive/2011/09/20/359014.html</link><dc:creator>lincode</dc:creator><author>lincode</author><pubDate>Tue, 20 Sep 2011 02:20:00 GMT</pubDate><guid>http://www.blogjava.net/lincode/archive/2011/09/20/359014.html</guid><wfw:comment>http://www.blogjava.net/lincode/comments/359014.html</wfw:comment><comments>http://www.blogjava.net/lincode/archive/2011/09/20/359014.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/lincode/comments/commentRss/359014.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lincode/services/trackbacks/359014.html</trackback:ping><description><![CDATA[<br />PhoneGap 是一个移动开发框架。通过 PhoneGap，开发者可以使用 JavaScript 调用手机的原生功能，例如，获取经纬度，让手机振动等。<br />主页&nbsp;http://www.phonegap.com/ 。<br />源码 https://github.com/phonegap/phonegap-android 。<br /><br />PhoneGap 在早期，应该是使用 WebView 的 addJavaScriptInterface 方法，来为 JS 提供调用原生功能可能。addJavaScriptInterface ，可以将一个 Java 对象绑定到一个 JS 对象。是的，JS对象可以调用 Java方法。但在 PhoneGap 1.0.0 这个版本中，PhoneGap 改变了方法。<br /><br />以振动功能为例，我们可以看一下程序调用的流程：<br /><strong><br />1 在 JS 中，启动命令</strong><br /><div>        <p>main.js / navigator.notification.vibrate(0);</p></div><div>         <p>notification.js / Notification.vibrate.vibrate 中执行了 PhoneGap.exec(null, null, "Notification", "vibrate", [mills]);</p></div>phonegap.js / PhoneGap.exc 中执行了&nbsp;var r = prompt(PhoneGap.stringify(args), "gap:"+PhoneGap.stringify([service, action, callbackId, true]));<br /><br />这时，WebView 就会企图弹出一个窗口。这时使用 android 提供的&nbsp;WebChromeClient 的&nbsp;API 就可以截获 WebView 的这个动作 。<br /><br /><strong>2 JAVA 中，处理命令<br /></strong>WebView 的 WebChromClient 实现了下面这个函数：<br /><div>        <p>public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result)</p></div>在 onJsPrompt 中执行了&nbsp;String r = pluginManager.exec(service, action, callbackId, message, async);<br /><br />PlugManager 会根据收到参数，将命令分发给特定的 Plugin。这个例子中，接收的 plugin 是：Notification。<br />落实到 Notification 的 exec 函数：会执行这一行：&nbsp;this.vibrate(args.getLong(0));<br /><br />振动的实现为：<br /><div>        <p>&nbsp;</p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;vibrate(</span><span style="color: #0000FF; ">long</span><span style="color: #000000; ">&nbsp;time){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;Start&nbsp;the&nbsp;vibration,&nbsp;0&nbsp;defaults&nbsp;to&nbsp;half&nbsp;a&nbsp;second.</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">&nbsp;(time&nbsp;</span><span style="color: #000000; ">==</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">0</span><span style="color: #000000; ">)&nbsp;{<br />time&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">500</span><span style="color: #000000; ">;<br />}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Vibrator&nbsp;vibrator&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;(Vibrator)&nbsp;</span><span style="color: #0000FF; ">this</span><span style="color: #000000; ">.ctx.getSystemService(Context.VIBRATOR_SERVICE);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vibrator.vibrate(time);<br />}</span></div><p>&nbsp;</p></div><br /><strong>3 Java 处理完后的数据，需要给 JS 一个反馈：</strong><br />这里 PhoneGap 使用了一个在客户端本地实现的 XHRServer，具体到代码中就是一个JAVA 类 CallbackServer。<br /><br />分两个部分介绍其行为：<br />本地 XHRServer，<br />思想是，后台每执行完一个命令，都会将结果存在 CallbackServer 中的一个链表中，具体为CallbackServr的 private LinkedList&lt;String&gt; javascript;<br />这个结果其实是一段字符串表示的 JS 函数调用。例如检测网络调用的结果为：PhoneGap.callbackSuccess('Network Status1',{status:1,message:"wifi",keepCallback:true});<br />&nbsp;XHRServer 的行为很简单，只要有请求来，就把链表中的最先进来的提出来，返回给客户端。没有请求来，则 10秒钟返回一个空的回复，以维持XHRServer。<div></div>Webview 作为客户端：<br />在 WebView 中，会有一个轮询机制，这可以参考 PhoneGap.JSCallack 和&nbsp;PhoneGap.JSCallbackPolling 两个函数来访问 XHRServer。XHRServer，返回的结果就是 WebView 需要调用的 JS 函数。 在 JS 中，eval() 函数，将返回的结果变为一个可以执行的对象，在 Webview 中执行，可以认为这即是回调函数 Callback。这也是为什么 PhoneGap 为何命名 XHRServer 为 CallbackServer 的原因。<br /><br /><img src ="http://www.blogjava.net/lincode/aggbug/359014.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lincode/" target="_blank">lincode</a> 2011-09-20 10:20 <a href="http://www.blogjava.net/lincode/archive/2011/09/20/359014.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[android] dip，dp，px，pt，sp 的区别</title><link>http://www.blogjava.net/lincode/archive/2011/09/16/358813.html</link><dc:creator>lincode</dc:creator><author>lincode</author><pubDate>Fri, 16 Sep 2011 09:58:00 GMT</pubDate><guid>http://www.blogjava.net/lincode/archive/2011/09/16/358813.html</guid><wfw:comment>http://www.blogjava.net/lincode/comments/358813.html</wfw:comment><comments>http://www.blogjava.net/lincode/archive/2011/09/16/358813.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/lincode/comments/commentRss/358813.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lincode/services/trackbacks/358813.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; background-color: #ffffff; ">dip: device independent pixels(设备独立像素)。不同设备有不同的显示效果，这个和设备硬件有关，一般我们为了支持WVGA、HVGA和QVGA 推荐使用这个，不依赖像素。&nbsp;<br /><br /></span><span class="Apple-style-span" style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; background-color: #ffffff; ">dp:（与密度无关的像素）一种基于屏幕密度的抽象单位。在每英寸160点的显示器上，1dp = 1px。&nbsp;<br /></span><span class="Apple-style-span" style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; background-color: #ffffff; "><br /></span><span class="Apple-style-span" style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; background-color: #ffffff; ">px:&nbsp;pixels(像素). 不同设备显示效果相同，一般我们HVGA代表320x480像素，这个用的比较多。&nbsp;<br /></span><span class="Apple-style-span" style="font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; background-color: #ffffff; "><br />pt: point(磅)，是一个标准的长度单位，1pt＝1/72英寸，用于印刷业，非常简单易用；&nbsp;<br /><br />sp: scaled pixels(放大像素). 主要用于字体显示best for textsize。&nbsp;</span><img src ="http://www.blogjava.net/lincode/aggbug/358813.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lincode/" target="_blank">lincode</a> 2011-09-16 17:58 <a href="http://www.blogjava.net/lincode/archive/2011/09/16/358813.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[android] Serializable 和 Parcelable 区别</title><link>http://www.blogjava.net/lincode/archive/2011/09/16/358805.html</link><dc:creator>lincode</dc:creator><author>lincode</author><pubDate>Fri, 16 Sep 2011 08:16:00 GMT</pubDate><guid>http://www.blogjava.net/lincode/archive/2011/09/16/358805.html</guid><wfw:comment>http://www.blogjava.net/lincode/comments/358805.html</wfw:comment><comments>http://www.blogjava.net/lincode/archive/2011/09/16/358805.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lincode/comments/commentRss/358805.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lincode/services/trackbacks/358805.html</trackback:ping><description><![CDATA[<br />android 中<span class="Apple-style-span" style="background-color: #ffffff; "><span class="Apple-style-span" style="color: #595959; font-family: Verdana, Arial, Helvetica, 宋体, sans-serif; line-height: 25px; "><span style="line-height: 21px; color: #333333; border-collapse: collapse; font-family: Arial; ">自定义的对象</span><span style="line-height: 28px; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; ">序列化的问题</span><span style="line-height: 21px; color: #333333; border-collapse: collapse; font-family: Arial; ">有两个选择一个是Parcelable，另外一个是Serializable。</span></span><p style="font-family: Verdana, Arial, Helvetica, 宋体, sans-serif; line-height: 25px; color: #595959; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span style="line-height: 21px; color: #333333; border-collapse: collapse; font-family: Arial; ">一 序列化原因：</span></p><p style="font-family: Verdana, Arial, Helvetica, 宋体, sans-serif; line-height: 25px; color: #595959; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span style="line-height: 21px; color: #333333; border-collapse: collapse; "><span style="line-height: normal; color: #000000; font-size: 13px; border-collapse: separate; "><font face="宋体" style="line-height: 23px; ">1.永久性保存对象，保存对象的字节序列到本地文件中；<br style="line-height: 23px; " />2.通过序列化对象在网络中传递对象；<br style="line-height: 23px; " />3.通过序列化在进程间传递对象。&nbsp;<br /><br /></font></span></span></p><p style="font-family: Verdana, Arial, Helvetica, 宋体, sans-serif; line-height: 25px; color: #595959; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span style="line-height: 21px; color: #333333; border-collapse: collapse; font-family: Arial; ">二 至于选取哪种可参考下面的原则：</span></p><p style="font-family: Verdana, Arial, Helvetica, 宋体, sans-serif; line-height: 25px; color: #595959; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><span style="line-height: 21px; color: #333333; border-collapse: collapse; font-family: Arial; ">1.在使用内存的时候，Parcelable 类比Serializable性能高，所以推荐使用Parcelable类。<br style="line-height: 25px; " />2.Serializable在序列化的时候会产生大量的临时变量，从而引起频繁的GC。<br style="line-height: 25px; " />3.Parcelable不能使用在要将数据存储在磁盘上的情况，因为Parcelable不能很好的保证数据的持续性在外界有变化的情况下。尽管Serializable效率低点， 也不提倡用，但在这种情况下，还是建议你用Serializable 。</span></p></span><br /><strong>实现：</strong><br />1 Serializable 的实现，只需要继承 &nbsp;implements Serializable 即可。这只是给对象打了一个标记，系统会自动将其序列化。<br /><br />2 Parcelabel 的实现，需要在类中添加一个静态成员变量 CREATOR，这个变量需要继承 Parcelable.Creator 接口。<br /><div style="font-weight: bold; background-color: #eeeeee; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">class</span><span style="color: #000000; ">&nbsp;MyParcelable&nbsp;</span><span style="color: #0000FF; ">implements</span><span style="color: #000000; ">&nbsp;Parcelable&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">private</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;mData;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;describeContents()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">0</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;writeToParcel(Parcel&nbsp;out,&nbsp;</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;flags)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out.writeInt(mData);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">static</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">final</span><span style="color: #000000; ">&nbsp;Parcelable.Creator</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">MyParcelable</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; ">&nbsp;CREATOR<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">new</span><span style="color: #000000; ">&nbsp;Parcelable.Creator</span><span style="color: #000000; ">&lt;</span><span style="color: #000000; ">MyParcelable</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; ">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;MyParcelable&nbsp;createFromParcel(Parcel&nbsp;in)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">new</span><span style="color: #000000; ">&nbsp;MyParcelable(in);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">public</span><span style="color: #000000; ">&nbsp;MyParcelable[]&nbsp;newArray(</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">&nbsp;size)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">new</span><span style="color: #000000; ">&nbsp;MyParcelable[size];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">private</span><span style="color: #000000; ">&nbsp;MyParcelable(Parcel&nbsp;in)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mData&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;in.readInt();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;}</span></div><br /><strong>&nbsp;</strong><img src ="http://www.blogjava.net/lincode/aggbug/358805.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lincode/" target="_blank">lincode</a> 2011-09-16 16:16 <a href="http://www.blogjava.net/lincode/archive/2011/09/16/358805.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[android] Activity 的生命周期 以及 横屏竖屏切换时 Activity 的状态变化</title><link>http://www.blogjava.net/lincode/archive/2011/09/16/358768.html</link><dc:creator>lincode</dc:creator><author>lincode</author><pubDate>Fri, 16 Sep 2011 02:32:00 GMT</pubDate><guid>http://www.blogjava.net/lincode/archive/2011/09/16/358768.html</guid><wfw:comment>http://www.blogjava.net/lincode/comments/358768.html</wfw:comment><comments>http://www.blogjava.net/lincode/archive/2011/09/16/358768.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/lincode/comments/commentRss/358768.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lincode/services/trackbacks/358768.html</trackback:ping><description><![CDATA[<strong>生命周期</strong><br /><span class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">Android 系统在Activity 生命周期中加入一些钩子，我们可以在这些系统预留的钩子中做一些事情。<br />例举了 7 个常用的钩子：<br style="line-height: 22px; " /></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">protected void onCreate(Bundle savedInstanceState)<br style="line-height: 22px; " /></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">protected void onStart()<br style="line-height: 22px; " /></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">protected void onResume()<br style="line-height: 22px; " /></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">protected void onPause()<br style="line-height: 22px; " /></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">protected void onStop()<br style="line-height: 22px; " /></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">protected void onRestart()<br style="line-height: 22px; " /></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">protected void onDestroy()<br /><br />简要说明：<br /></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">onCreate(Bundle savedInstanceState)：创建activity时调用。设置在该方法中，还以Bundle中可以提出用于创建该 Activity 所需的信息。<br style="line-height: 22px; " /></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">onStart()：activity变为在屏幕上对用户可见时，即获得焦点时，会调用。<br style="line-height: 22px; " /></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">onResume()：activity开始与用户交互时调用（无论是启动还是重新启动一个活动，该方法总是被调用的）。<br style="line-height: 22px; " /></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">onPause()：activity被暂停或收回cpu和其他资源时调用，该方法用于保存活动状态的。。<br style="line-height: 22px; " /></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">onStop()：activity被停止并转为不可见阶段及后续的生命周期事件时，即失去焦点时调用。<br style="line-height: 22px; " /></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">onRestart()：重新启动activity时调用。该活动仍在栈中，而不是启动新的活动。<br style="line-height: 22px; " /></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">onDestroy()：activity被完全从系统内存中移除时调用，该方法被调用可能是因为有人直接调用 finish()方法 或者系统决定停止该活动以释放资源。<br /></span><br /><strong>横竖屏切换</strong><br /><br />1 切换到横屏<br /><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onSaveInstanceState<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onPause<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onStop<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onDestroy<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onCreate<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onStart<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onRestoreInstanceState<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onResume<br /><br /></span>2 切换到竖屏，销毁了两次<br /><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onSaveInstanceState<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onPause<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onStop<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onDestroy</span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onCreate<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onStart<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onRestoreInstanceState<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onResume<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onSaveInstanceState<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onPause<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onStop<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onDestroy<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onCreate<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onStart<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onRestoreInstanceState<br /></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onResume</span><br /><br /><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #f5fafe; "><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">3 修改AndroidManifest.xml，把该Activity添加 android:configChanges="orientation"，切横屏，只销毁一次。</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">onSaveInstanceState<br />onPause<br />onStop<br />onDestroy<br />onCreate<br />onStart<br />onRestoreInstanceState<br />onResume</p></span>4&nbsp;<span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #f5fafe; ">再切回竖屏，发现不会再打印相同信息，但多打印了一行onConfigChanged<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">onSaveInstanceState<br />onPause<br />onStop<br />onDestroy<br />onCreate<br />onStart<br />onRestoreInstanceState<br />onResume<br />onConfigurationChanged</p></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #f5fafe; "><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">5 更改 android:configChanges="orientation" 改成 android:configChanges="orientation|keyboardHidden"，切横屏，就只打印onConfigChanged</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">onConfigurationChanged</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">6 切回竖屏</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">onConfigurationChanged<br />onConfigurationChanged</p></span><span class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #f5fafe; "><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">总结：</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">1、不设置Activity的android:configChanges时，切屏会重新调用各个生命周期，切横屏时会执行一次，切竖屏时会执行两次</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">2、设置Activity的android:configChanges="orientation"时，切屏还是会重新调用各个生命周期，切横、竖屏时只会执行一次</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">3、设置Activity的android:configChanges="orientation|keyboardHidden"时，切屏不会重新调用各个生命周期，只会执行onConfigurationChanged方法</p></span><br /><br /><br /><br /><img src ="http://www.blogjava.net/lincode/aggbug/358768.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lincode/" target="_blank">lincode</a> 2011-09-16 10:32 <a href="http://www.blogjava.net/lincode/archive/2011/09/16/358768.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>