2017年12月25日 星期一

for xamarin ios,javascript call back to UIView

有些程式在web已經寫好了,想要xamarin UI中應用的話,
就ios而言,就可以利用"WebKit"了
今天就先討論從javascript丟回來呼叫xamarin UI怎麼做
==============某個要查看網頁的viewcontroller======
    public partial class MyMapViewController : UIViewController, IWKScriptMessageHandler {
        public MyMapViewController () : base("MyMapViewController ", null) {
        }

        public override void DidReceiveMemoryWarning() {
            base.DidReceiveMemoryWarning();
         
            // Release any cached data, images, etc that aren't in use.
        }

        public override void ViewDidLoad() {
            base.ViewDidLoad();

            var userController = new WKUserContentController();
            userController.AddScriptMessageHandler(this, "myApp");
            var config = new WKWebViewConfiguration {
                UserContentController = userController
            };
            var webkitView= new WebKit.WKWebView(viewContainScroll.Frame, config);
            webkitView.LoadRequest(new Foundation.NSUrlRequest(new NSUrl("你的web網址")));
            webkitView.ContentMode = UIViewContentMode.ScaleToFill;
            this.View.AddSubview(webkitView);
       }

public void DidReceiveScriptMessage(WKUserContentController userContentController,           WKScriptMessage message) {
            var msg = message.Body.ToString();
            System.Diagnostics.Debug.WriteLine(msg);
        }

============================================
手機端好了,再來就是看遙遠的雲端了
===============================
 <html>
   <body>
    <script type="text/javascript">
       //找個按鈕觸發這個doCallBack吧
       var doCallBack = function ( paraStr) {
            //以下的動作就會呼叫包含他的webkitview所AddScriptMessageHandler的物件的     
            //「DidReceiveScriptMessage」的函數來接受訊息了
            window.webkit.messageHandlers.myApp.postMessage("param=" + paraStr);
        }
         ...
         ...
         .....
    </script>
   </body>
</html>
================================
完整的討論來源,請參考這裡
現在的前端的工程師不只是二刀流的,
通常是剪刀菜刀剃頭刀手術刀小李飛刀都要會了

2017年12月22日 星期五

繪製半透明的png於底圖上之

正如同「身為一個汽車維修員,有個錘子在身邊,也很合邏輯」一樣
工程師嘛,圖片加工也要會是很自然不過的事了,特別是你有用到平面圖的機制時
「I am here」標示本來是不需要半透明的,基於方便參考其他地標時,還是給個半透明的版本好了
===================================================
               ...
               ...
              ...
              var Alpha=0.55f;
                Bitmap bmpIamHere = new Bitmap(imgIamHereIcon);
                Color background = bmpIamHere.GetPixel(0, 0);
                 //設定透明色為.....
                bmpIamHere.MakeTransparent(background);
                Graphics gfxMap = Graphics.FromImage(imgMap);
                //set alpha value.
                ColorMatrix cm = new ColorMatrix();
                cm.Matrix33 = Alpha;
                ImageAttributes ia = new ImageAttributes();
                ia.SetColorMatrix(cm);
             
                //沒有 Alpha值時,直接繪製,gfxMap.DrawImage(bmpIamHere, (float)markAtX, (float)markAtY, bmpIamHere.Width, bmpIamHere.Height);
               //有alpha值時,請用以下方式
                gfxMap.DrawImage(bmpIamHere, new Rectangle((int)markAtX, (int)markAtY, bmpIamHere.Width, bmpIamHere.Height), 0, 0, bmpIamHere.Width, bmpIamHere.Height, GraphicsUnit.Pixel, ia);
                ...
               ...
               ...
=================================================
來源在此

加油了

2017年12月20日 星期三

ERROR ITMS-90502: "Invalid Bundle. Apps that only contain the arm64 slice must also have 'arm64' in the list of UIRequiredDeviceCapabilities in Info.plist."

在用 application Launcher 上傳ipa到 iTunes connect  時
遇到以下的狀況:
「ERROR ITMS-90502: "Invalid Bundle. Apps that only contain the arm64 slice must also have 'arm64' in the list of UIRequiredDeviceCapabilities in Info.plist."」
這樣的問題直接就是去Info.plist去改:
==============================
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
===============================
(從原來的armv7改成arm64就可以了)
記得:就算是只做testflight,也要把media.xcassets中的 icon都指定完才可以上beta測試
還有,用application launcher上傳完ipa檔後,不要只是在  iTunes connect的web介面去看「activities/活動」看它有沒有上傳
有時.......是不會出現的, iTunes connect會把問題寄到你的email而不是在application launcher上傳驗證後就直接給你答案.
多注意點不同的資訊管道吧

2017年12月10日 星期日

for xamarin android :如何自行觸發FCM中 service「onTokenRefresh」事件

相信大家都已經會基本的FCM的推播架構了
不過,或許你會問「如何觸發FirebaseInstanceIdService 中的OnTokenRefresh事件」
 官方的回應是安裝,反安裝套件,或是過一段時間會重行配置token
有個不錯的觸發方式可以參考
=======在某個activity中=================
 ...
...
... 按鈕click事件

btnDeleteToken.Click +=  delegate (object sender, EventArgs e) {
                 //注意,deleteFcmInstanace一定要另起執行緒執行,不能在MAIN_THREAD中執行
                var th = new System.Threading.Thread(
                      () => {
                          deleteFcmInstanace();
                      }
                 );
                th.Start();
            };
...
...
...
void deleteFcmInstanace(){
                Firebase.Iid.FirebaseInstanceId.Instance.DeleteInstanceId();
                Log.Debug("DONE", "delete token works");
               //一定要再InitializeApp,否則取得的token是null的
              //以下動作執行後,就會觸發FirebaseInstanceIdService 中的OnTokenRefresh事件
                Firebase.FirebaseApp.InitializeApp(this);
 var refreshedToken = Firebase.Iid.FirebaseInstanceId.Instance.Token;
}

====================================
做這事是有點不實際,只是想要驗證一下罷了,大家應該用不到
不過「好奇心」是所有programmer應該有的吧



2017年11月28日 星期二

怎麼改,MonoAndroid,Version 都是錯的!?


在升級android一些套件時(尤其是FCM需要的googplayservice.base)會遇到以下的相關套件狀況
=============================
無法安裝封裝 'Xamarin.Android.Support.Compat 24.2.1'。您正嘗試將此封裝安裝到以 'MonoAndroid,Version=v5.0' 為目標的專案,但該封裝不包含任何與架構相容的組件參考或內容檔。如需詳細資訊,請連絡封裝作者。

==============================
這時,除了參考:
http://neo-tech-tw.blogspot.tw/2017/08/vs2015xamarinupdate.html
到xamarin總站去下載xamarin.android setup安裝之外
還要去vs的android  的SDK manager下載比較高級的SDK版本(7.11...當然愈齊全愈好)

最重要的是要去這個android的project properties設定target frameowork到「Android 7.1(Nougat)」

存檔,然後,離開,再重新進入vs
記得,只改專案的屬性檔存檔就去Nuget做udpate還是會有最初MonoAndroid version的錯誤,
只有重新進入vs才有用

2017年11月27日 星期一

無法載入組件..... ICSharpCode.SharpZipLib, Version=0.86.0.518

Could not load file or assembly CSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73'  ......

寫的這麼落落長,好像很多人也遇到這問題,
有的解法是去改"<SpecificVersion>False</SpecificVersion>"
(ref: https://github.com/icsharpcode/SharpDevelop/issues/605 )

有的是去改token 
ref: http://www.cnblogs.com/zinan/p/5075903.html

有的是請你去參考那裡改抓dll存在package中的路徑

而我,最後是用這招 :到「工具」->「NuGet封裝管理員」-->「套件管理器主控台」
那裡下指令「Install-Package ICSharpCode.SharpZipLib -Version 0.86.0.518」
就解決這個很麻煩的問題了

參考這裡

(如果是開發web 應用程式的話,不能只update bin資料夾,還要記得把在web.config相關組件的訊息一併update到正式站台去,否則還是錯的)

大家加油了

2017年10月24日 星期二

mvc4->mvc5發生這樣的錯誤「[A]System.Web.WebPages.Razor.Configuration.HostSection 無法轉型為 [B]System.Web.WebPages.Razor.Configuration.HostSection.」

======升級MVC4 to MVC5時,發生了Razor版本的問題=====

[A]System.Web.WebPages.Razor.Configuration.HostSection 無法轉型為 f[B]System.Web.WebPages.Razor.Configuration.HostSection. 類型 A 源自 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' (在內容 'Default' 中,位置為 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'). 類型 B 源自 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' (在內容 'Default' 中,位置為 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\.....\183bffad\c40c5844\assembly\dl3\ea4310d4\00dbbd75_6c3ad001\System.Web.WebPages.Razor.dll').

=============================================
這時,請到View之下的web.config.
找出<section name="host" type ....>
及<section name="pages" type=....>
兩個節點中的「Razor, Version=2.0.0....」改為「Razor,  Version=3.0.....」
如下圖:

以上,大家加油了

2017年10月21日 星期六

for Extj4 grid 讓某欄允許多行文字折行顯示

extjs5 是在column中設定「 cellWrap: true」就可以了
但是在Extjs4呢?
需要在css中設定一下了,基本上不出white-space:normal 這個設定,
參考http://jaspreetchahal.org/extjs-grid-multi-line-rows/

但如果你要直接寫在某欄位的話
就直接寫在randerer吧,
別忘了加入「important」這個複寫指令
如:
==========果然important不是叫假的=========
renderer: function (value, metaData, record, rowIndex, colIndex, store, view) {
                                return '<div style="white-space:normal !important;">' + value + '</div>';
                            },
==================================

以上,大家加油了

2017年9月30日 星期六

如何在你的windows中輸出Base64 X509憑證

參考影音:
https://www.youtube.com/watch?v=PXopk5RbDbc
但是在「匯出私密金鑰」時,選「否,不要匯出私密金鑰」之後那頁就有Base64 X509格式了
win. 8.1在cmmand.com輸出mcc.exe時不會出現mmc,會出現hyperV 管理員
這時要用系統管理員的權限啟動command.com再輸入mmc就會出現了

2017年8月19日 星期六

for xamarin 如何繪製一二維條碼

二維的比較簡單,先講二維的好了
不用ZXing,直接用CG--CoreGraphic套件就可以了
============================================
            /*
            Correction level option as below:
            L, // Level L (Low) 7% of codewords can be restored.
    M, // Level M (Medium) 15% of codewords can be restored.
           Q, // Level Q (Quartile) 25% of codewords can be restored.
            H // Level H (High) 30% of codewords can be restored.          
             */
            CoreImage.CIQRCodeGenerator ciQrCodeGen = new CoreImage.CIQRCodeGenerator() {
                Message = NSData.FromString("這裡面可以裝下1700多個漢字,請好好發揮了"),
                CorrectionLevel = "L",
            };
            var context = CoreImage.CIContext.FromOptions(null);
            //假設有個UIImageView叫imgQrCode,放置二維條碼
            imgQrCode.Image=UIImage.FromImage(
                context.CreateCGImage(ciQrCodeGen.OutputImage,ciQrCodeGen.OutputImage.Extent)
            );
============================================

相形之下,一維比較麻煩(以39碼為例):
---------------------------step1:-------------------------------------------------------
public interface IBarcodeService {
        Stream ConvertImageStream(string text, int width = 300, int height = 130);
    }
---------------------------step2:-------------------------------------------------------
class BarcodeService : IBarcodeService {
        public Stream ConvertImageStream(string text, int width = 300, int height = 130) {
            var barcodeWriter = new ZXing.Mobile.BarcodeWriter {
                Format = ZXing.BarcodeFormat.CODE_39,
                Options = new ZXing.Common.EncodingOptions {
                    Width = width,
                    Height = height,
                    Margin = 10
                }
            };
            barcodeWriter.Renderer = new ZXing.Mobile.BitmapRenderer();
            var bitmap = barcodeWriter.Write(text);
            var stream = bitmap.AsPNG().AsStream(); // this is the difference
            stream.Position = 0;

            return stream;
        }
---------------------------step3:-------------------------------------------------------
//假設我們要把一維條碼繪在UIImageView "imgCode39"上面...
var stream =new  Barcode.BarcodeService().ConvertImageStream("10607UP197419461A5B");
 imgCode39.Image= UIImage.LoadFromData(Foundation.NSData.FromStream(stream));


參考:https://forums.xamarin.com/discussion/28161/barcode-rendering-with-zxing-net-in-my-xamarin-forms-app

 大家加油了