2010/04/26

iPhone 開發 Web 應用程式小技巧

1.特殊連結

Google Map http://maps.google.com/maps?q=<地址>
電話 call:
簡訊 sms:
郵件 mailto:

2.iPhone 桌面上建立圖示

圖示大小:57 x 57px   

增加 <link rel="apple-touch-icon" href="<圖片網址>" />

例如 Hami.emome.net  http://hami.emome.net/img/hami_WebClip.png

3.版面調整

Safari on iPhone 預設版型會以一般(桌上型)呈顯,但如果下了以下這行,會直接以 iPhone 寬度限制住(如 320px or 480px)

<meta name="viewport" content="width=device-width" />

預設縮放比例為 1

<meta name="viewport" content="initial-scale = 1.0" />

詳細 viewport 參考文件

<meta name="apple-mobile-web-app-status-bar-style" content="black" />

 

4.強制不偵測電話號碼

<meta name="format-detection" content="telephone=no">
 

5.隱藏網址列Hide address bar

<script type="text/javascript">
    if (navigator.userAgent.indexOf('iPhone') != -1) {
        addEventListener("load", function() {
            setTimeout(hideURLbar, 0);
        }, false);
    }
    function hideURLbar() { window.scrollTo(0, 1); }
</script>  

 

 

 

 

相關連結

Safari Dev Center

http://developer.apple.com/safari/

iPhone Development: 12 Tips To Get You Started

http://articles.sitepoint.com/article/iphone-development-12-tips

Sarafi HTML Ref

http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariHTMLRef/Introduction.html

Sarafi HTML Ref - PDF Version

http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariHTMLRef/SafariHTMLRef.pdf

Sarafi User Guide Ref

http://developer.apple.com/safari/library/documentation/AppleApplications/Conceptual/Safari_Developer_Guide/1Introduction/Introduction.html

Sarafi User Guide Ref - PDF Version

http://developer.apple.com/safari/library/documentation/AppleApplications/Conceptual/Safari_Developer_Guide/Safari_Developer_Guide.pdf

 

 

 

 

如何讓 IE/Firefox/Chrome 可以模擬 iPhone 網頁?

安裝 Fiddler 後,透由 Customize Rules 變更 User-Agents 來進行模擬!!

 

image

public static RulesOption("IE &7 (Vista)", "&User-Agents", true)
var m_IE7: boolean = false;

之下增加:

public static RulesOption("IPHONE", "&User-Agents", true)
var m_IPHONE: boolean =false;

還有另一段

if (m_IE7){
    oSession.oRequest["User-Agent"] = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1)";
}
else

之下增加

if (m_IPHONE){
    oSession.oRequest["User-Agent"] = "iPhone;Mozilla/4.0 (compatible; iphone;)";
}

else

存檔後關閉就會在下圖中出現 IPHONE

image

2010/04/23

WCF 歷險記

WCF Test Client Tool

  • SOA Cleaner
    • 好用,但是不是免費
    • 支援 DataTable / DataSet
    • 不支援 maxBufferPoolSize , maxReceivedMessageSize
  • WCFTestClient.exe (Build in Visual Studio)
    • C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\WcfTestClient.exe
    • 不支援 DataTable / DataSet

 

Q:呼叫多次出現 cannot be used for communication because it is in the Faulted state.

A:http://msdn.microsoft.com/en-us/library/aa355056.aspx

Client 避免使用 Using 改用 Try...Catch...

WCF Client Avoiding Problems with the Using Statement

Aa355056.note(en-us,VS.100).gifNote:

The using statement and ServiceHost: Many self-hosting applications do little more than host a service, and ServiceHost.Close rarely throws an exception, so such applications can safely use the using statement with ServiceHost. However, be aware that ServiceHost.Close can throw a CommunicationException, so if your application continues after closing the ServiceHost, you should avoid the using statement and follow the pattern previously given.

=====

Q: WCF Proxy Class can not generated 無法自動產生 Service Reference?

A: 有可能含有 WCF 不支援的型別,例如 DateTime?
可以使用 DataContractAttribute 排除

http://msdn.microsoft.com/zh-tw/library/system.runtime.serialization.datacontractattribute%28VS.90%29.aspx

=====

Q:為什麼回傳 DataTable 會出現錯誤?

A:序列化時 DataTable.TableName 為必填欄位,要記得指定。

=====

Q:為什麼無法回傳 Enum 型別?

A:需設定 [EnumMember] 在 Client 才會出現正確

範例:

[DataContract]
public enum FuncRight { [EnumMember]Read, [EnumMember] Edit };

Sharing Enum with WCF Service

2010/04/16

KB-Report Viewer Control Localization

最近 Web 使用了 Report View Control 來做為報表的呈顯,但是 Server 安裝版本是 English,無法呈顯多語系

Microsoft Report Viewer 2008 SP1 Redistributable

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=bb196d5d-76c2-4a0e-9458-267d22b6aac6

結果報表呈現上就是英文

image

試了很久,後來發現 Report View 有 Language Pack

Microsoft Report Viewer Redistributable 2008 SP1 语言包-簡體中文

http://www.microsoft.com/downloads/details.aspx?displaylang=zh-cn&FamilyID=c1df3b07-09d7-48cb-bb63-df6d3c2f8141

Microsoft 可轉散發報表檢視器 2008 SP1 語言套件-繁體中文

http://www.microsoft.com/downloads/details.aspx?familyid=C1DF3B07-09D7-48CB-BB63-DF6D3C2F8141&displaylang=zh-tw

image

安裝後就可以依據 Browser 的語言來做切換,另外在 Server 上也可以定義:

1.Page

<%@ Page Language="C#" ...... Culture="zh-tw" %>

2.Web.config

<System.Web>

         <globalization uiCulture="zh-tw" culture="zh-tw" />

</System.Web>

 

比較方便的方法是直接安裝繁體中文版的 Report View ,就會內含繁中+英文。

Microsoft Report Viewer 2008 SP1 Redistributable - 繁體中文

http://www.microsoft.com/downloads/details.aspx?familyid=BB196D5D-76C2-4A0E-9458-267D22B6AAC6&displaylang=zh-tw