2019年6月3日 星期一

iOS swift 5: About "Unprintable ASCII character found in source file"

"Unprintable ASCII character found in source file"
有一些中文字在 swift String Source Code中就會發生

解決方案來源:
  iOS - 關於多國語系的那些事(Localization)
  iOS - 在 App 內切換語系

解決方法
 把中文字串放到 Localizable.strings中
  \zh-Hant.lproj\Localizable.strings
 再使用 NSLocalizedString() 取出
  let MyStriug = NSLocalizedString("56022", comment: "")

2019年5月23日 星期四

iOS swift 5: 關於兩個時間之間的時間差

關於兩個時間之間的時間差

解決方案來源:
swift 对日期的处理大全


 var Date1: Date = Date()
 var Date2: Date = Date()
 let nInterval = Date2.timeIntervalSince(Date1)

macOS: 超注音

原有 MacOS上的注音輸入法太難用 都亂猜字
這個輸入法現在用的還算不錯
試用版 30天
每次重新開機後, 第一次切換到中文輸入, 常常會失效
請用滑鼠點一下去切換,
切換成功後,未重新開機前, 使用上都滿順的.

產品: 超注音 for macOS
不限制 MacOS 電腦數量, 但只能用在MacOS不可用在 iPhone, iPad
下載: 超注音 for macOS Ver 1.0.6

購買用於 MacOS電腦
費用: NT$500元


小麥注音輸入法是一套免費macOS專用輸入法
有多種注音的鍵盤配置模式
McBopomofo 小麥注音輸入法

另外還有一套多種平台的免費輸入法
但注音的鍵盤配置只有傳統排列方式
  中州韻輸入法引擎


2019年5月22日 星期三

iOS swift 5: 關於 "UIAlertController actionSheet Exception"


解決方案來源:
1: 顯示警告訊息和選單的 UIAlertControlle
2: Swift 4 Tutorial : Show PopOver with TableView from Scratch (Source file link in 
description)
3: ActionSheet Popover on iPad in Swift

 *** Terminating app due to uncaught exception
 'NSGenericException', reason: 'Your application has presented a
  UIAlertController (<UIAlertController: 0x1160ef600>) of
   style UIAlertControllerStyleActionSheet from XXX.MainViewController (<XXX.MainViewController: 0x116036600>).
   The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. You must provide
   location information for this popover through the alert controller's popoverPresentationController. You must provide
   either a sourceView and sourceRect or a barButtonItem.  If this information is not known when you present the alert

   controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.'

意思就是沒有設置UIAlertController這個彈出窗口的位置信息



 @IBAction func BtnTestOnClick(_ sender: Any)
 {
    
  let alertController = UIAlertController(title: nil, message: "Alert message.", preferredStyle: .actionSheet)

  let defaultAction = UIAlertAction(title: "Default", style: .default, handler: { (alert: UIAlertAction!) -> Void in
    //  Do some action here.
  })

  let deleteAction = UIAlertAction(title: "Delete", style: .destructive, handler: { (alert: UIAlertAction!) -> Void in
    //  Do some destructive action here.
  })

  let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: { (alert: UIAlertAction!) -> Void in
    //  Do something here upon cancellation.
  })

  alertController.addAction(defaultAction)
  alertController.addAction(deleteAction)
  alertController.addAction(cancelAction)
  
  if let popoverController = alertController.popoverPresentationController {
   popoverController.sourceView = self.view
   popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
   popoverController.permittedArrowDirections = []
  }

  self.present(alertController, animated: true, completion: nil)
 }

iOS swift 5: 關於 "CoreBluetooth XPC connection invalid"

CBCentralManager 這個class, 真的很不容易使用,限制滿多的.

解決方案來源:
ShenYun's Memo: iOS CoreBluetooth swift 2 連線客製化藍芽 BLE 模組 - ( 2 ) 連線
swift - CoreBluetooth XPC connection invalid - Stack Overflow


解說
 1: 專案的 Target -> Capabilities -> Background Modes -> 勾選兩個 Bluetooth LE Accessor

 2: info.plist 要加上
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Play with BLE Compatible devices</string>

 3: 把 CBCentralManager 放在一個 Class中

class TBleDeviceConnect: NSObject, CBCentralManagerDelegate, BPeripheralDelegate
{
   var centralManager: CBCentralManager! = nil
   func centralManagerInit()
   {
    centralManager = CBCentralManager.init(delegate: self, queue: nil, options: [CBCentralManagerOptionShowPowerAlertKey: true])
   }
}

 4: 把包含 CBCentralManager Class放到 MainViewController 中
     CBCentralManager一定要在 UIViewController中
class MainViewController: UIViewController
{
   /* Class Bluetooth CBCentralManager Control */
   var BleDeviceConnect: TBleDeviceConnect! = nil
}

 5: 如果是用在其他的 ViewController
    用 prepare for segue 方法將 CBCentralManager傳遞過去
    請參考 iOS swift 5: About Segue Prepare to NavigationController 

 6: 如果是在 Thread Function 中使用
DispatchQueue.main.async
{
 self.BleDeviceConnect.centralManagerInit()  
}

 7: 同一個Class 中的CBCentralManager 只能呼叫一次 centralManager = CBCentralManager.init(...)
   就會發生 "CoreBluetooth XPC connection invalid"
   解決方法還在尋找中....
   所以現在的做法呼叫 scanForPeripherals來重新掃描 Bluetooth Device











iOS swift 5: 關於 Segue Prepare to NavigationController


解決方案來源:
ios - Swift : prepareForSegue with navigation controller - Stack Overflow

class MainViewController: UIViewController
{
   /* Class Bluetooth CBCentralManager Control */
   var BleConnectDevice: TBleDeviceConnect! = nil
    override func prepare(for segue: UIStoryboardSegue, sender: Any?)
    {
     if( segue.identifier == "SegueOptions")
     {
      let destinationNavigationController = segue.destination as! UINavigationController
      let OptionsVc = destinationNavigationController.topViewController as! OptionsTableViewController
      OptionsVc.BleScannerDevice = self.BleScannerDevice
     }
    }
}

class OptionsTableViewController: UITableViewController, UITextFieldDelegate
{
    var BleScannerDevice: TBlueScannerDevice! = nil
    @IBAction func BtnBleOnClick(_ sender: Any)
    {
      DispatchQueue.main.async
      {
       self.BleScannerDevice.CentralManagerInit()
      }
    }
}

class TBleDeviceConnect: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate
{
    var cCentralManager: CBCentralManager! = nil
    func CentralManagerInit()
    {
     cCentralManager = CBCentralManager.init(delegate: self, queue: nil, options: [CBCentralManagerOptionShowPowerAlertKey: true])
    }
}


2018年11月26日 星期一

關於 Embarcadero RAD Studio 10.3 for iOS



終於把 MCU 部份搞定了
開始回來測試 ERS for iPad
但測試版的序號到期, 暈!

//==========================================================
RAD Studio 10.3 Rio (Update 1) 
10.3 Rio - Release 1
New features and customer reported issues fixed in RAD Studio 10.3.1
RAD Studio 10.3.1 is here, Happy Birthday Delphi!
delphicbuilder10_3_1_194899.iso
//==========================================================

//==========================================================
現在測試版的序號到期, 而且有一些技術上疑問也找不到解決方案
(已購買ERS可以找 Taiwan FAE 解決及詢問)

現在已改用Xcode + swift
雖然swift比不上 ERS 方便及好用
但至少遇到的疑問在 Google 都找的到答案

在使用Xcode swift開發 iOS APP期間, ERS開發者介面比 Xcode 強大好多.
Swift的程式語法及架構, 有點無言 
//==========================================================
iOS Development 可以在實機 iPad 上執行及 Step by Step Debug

iOS Ad Hoc Deploy ipa file 可以在實機 iPad 上執行

iOS Applicaption Store Deploy ipa file 是無法直接在實機 iPad 上測試
   請參考 Running the Application的解釋
   應該是要先上架 Apple App Store後, 再從App Store下載及安裝, 才能在 iPad 實機上測試.
   如果有其他的解決方案 請告知我

//==========================================================

iPad 6th (iOS 12.11)必須配合 Xcode 10.1,  ERS 才能執行
BCB 還是落後 Delphi 一代,
(Delphi可以在 iOS 12.11執行, BCB 確會出現錯誤)
把退回舊版Xcode 9.1, 那這樣 iPad 新版本作業系統的就無法執行
所以....

enum {
DISPATCH_WALLTIME_NOW DISPATCH_ENUM_API_AVAILABLE
(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0)) = ~1ull,
};

[bccosx Error] time.h(71): E2324 Numeric constant too large



Delphi 就沒有上述的問題

//==========================================================

BCB Debug Watch List 無法看到iPad 的變數
只能用猜的嗎?



//==========================================================
[PAClient Error] Error: E0264 Unable to execute '"/usr/bin/codesign" --deep -s
"iPhone Distribution: XXXX CO., LTD. (123F45CWXX)" -f
"/Users/jun/PAServer/scratch-dir/macOS 10.13.6/tt.app"' (Error 1)
這是 ERS 使用 PAServer 進行 codesign Certificate app 的指令

//==========================================================
[PAClient Error] Error: E0264 iPhone Distribution: XXXX CO., LTD. (123F45CWRC):
 ambiguous (matches "iPhone Distribution: XXXX CO., LTD. (123F45CWRC)"
  and "iPhone Distribution: XXXX CO., LTD. (123F45CWXX)"
   in /Users/jun/Library/Keychains/login.keychain-db)

這是因為點了 XCode -> Account -> Manage Certificate  -> + -> iOS Distribution
造成iPhone Distribution重覆的問題



//==========================================================
ERS 把一些 Apple Developer Certificates 流程省略, 沒有解釋清楚要如何設定,
造成開發者要自行研究這一部份.

關於Apple 憑證的設定, 請務必先看這篇, 雖然 Xcode 10.1有一點修改, 但原則上相通的


 http://delphi.ktop.com.tw/board.php?cid=32&fid=107&tid=109133
沒有這篇的解釋, 我一定做不出來一個 iPad APP
感謝分享!

搞了好幾天, 都做不出來.
就是少做了 "Worldwide Developer Relations Certificate Authorith" 下載及點選

//==========================================================
Could not locate device support files.
This iPad (6th generation) (Model A1893) is running iOS 12.1.1 (16C50), which may not be supported by this version of Xcode.

因為 iPad 版本比較新 (Apple 不讓使用舊版 iOS)
所以表示要改安裝 XCode 10.1 版本

//==========================================================

ID: 30869, December 2018 Missing Files Patch for 10.3
  December 2018 Missing Files Patch for 10.3

Mobile Tutorials: Mobile Application Development (iOS and Android)
for Rad Studio 10.2 Tokyo 


1: 可以支援 XCode 10.1  版本
     https://developer.apple.com/download/more/

2: 還是只能支援 XCode iOS 10.3 simruntime
    (請開啟 XCode 中點選下載)
3: 安裝後 Android SDK並沒有安裝完整
修正如下:
先刪除 SDK Manager 中的 Android SDK 25.2.5 32bit
C:> CD C:\Users\Public\Documents\Embarcadero\Studio\20.0\CatalogRepository\AndroidSDK-2525_20.0.32429.4364\tools
或者是
C:> CD C:\Users\Public\Documents\Embarcadero\Studio\20.0\PlatformSDKs\android-sdk-windows\tools

重建一個 Android SDK 25.2.5 32bit
C:> android.bat update sdk --no-ui --all --filter platform-tools,build-tools-28.0.2,android-26

Android SDK 路徑如下
C:\Users\Public\Documents\Embarcadero\Studio\20.0\CatalogRepository\AndroidSDK-2525_20.0.32429.4364
Android NDK 路徑如下
C:\Users\Public\Documents\Embarcadero\Studio\20.0\CatalogRepository\AndroidNDK-17b_20.0.32429.4364


//==========================================================
關於Apple 憑證的設定, 請務必先看這篇, 雖然 Xcode 10.1有一點修改, 但原則上相通的
 http://delphi.ktop.com.tw/board.php?cid=32&fid=107&tid=109133

//==========================================================

問題: can't start debugserver on device - device support image was not mounted


這是奇怪的現象, 簡單的說就是
(一定要使用Apple 原廠的USB線材)
Step 1: 先把 iPad 拔除和 iMac 取消連接
Step 2: 開啟 Xcode -> Windows -> Devices -> Devices
Step 3: iPad 和 iMac 連接
Step 4: 重新啟動 ERS Delphi Debug


//==========================================================
問題: unable to match bundle identifier
ERS Delphi Project -> Options -> Version Info
 CFBundlenName 和 CFBundleIdentifier  要設定為 App IDs
 CFBundlenName  => Project Name
 CFBundleIdentifier  => com.xxx.ProjectName
Project Debug / Release 都要設定


//==========================================================
問題:  Invalid compiler directive: 'false'
重新點選 ERS Delphi Project -> Options -> Debug Information



//==========================================================
Step 1:
 開啟 鑰匙圈存取.app
  Menu -> 鑰匙圈存取 -> 偏好設定 -> 重置我的預設鑰匙圈
  Menu -> 鑰匙圈存取 -> 憑證輔助程式 -> 從憑證授權要求憑證
  產生
   CertificateSigningRequest.certSigningRequest
Step 2:
 To developer.apple.com
 ISO,tvOS, watchOS
  Certificate
   All
    iOS Certificate => click +
     Select  "Worldwide Developer Relations Certificate Authorith"
     Download "AppleWWDRCA.cre"
   
Step 3:
 macOS
 鑰匙圈存取.app -> Click "登入" -> Click "憑證"
 Find app -> Double Click "AppleWWDRCA.cre"
 我的建議是這時最好把 macOS 重新開機
 再開啟鑰匙圈存取, 一定要在憑證中看到 "Apple Worldwide Developer Relations Certificate Authorith"
 沒有的話, 請重點 "AppleWWDRCA.cre"或等個幾分鐘, 再重新開機
 反正一定要出現, 沒出現的話, 後面步驟都是無效的
 PS: 要注意查看一下 AppleWWDRCA的有效期限.

Step 4:
 To developer.apple.com
 ISO,tvOS, watchOS
  Certificate
   All
    iOS Certificate => click +
    => Click "IOS App development"
    => Continue
    => Continue
    => Choose File -> "CertificateSigningRequest.certSigningRequest"
    => Continue
    => Download -> iOS_development.cre
    => Done
 
Step 5:
 To developer.apple.com
 ISO,tvOS, watchOS
  Certificate
   All
    => iOS Certificate
     => click +
     => Click "App Store and Ad Hoc"
     => Continue
     => Continue
     => Choose File -> "CertificateSigningRequest.certSigningRequest"
     => Continue
     => Download -> iOS_distribution.cre
     => Done
 
Step 6:
 To developer.apple.com
 ISO,tvOS, watchOS
  Idenifiers
   => App IDs
    => click +
    => App ID Description
      Name ->  myprojectname
    => Click "Explicit App ID"
    => Bundle ID ->  tw.com.mydomain.myprojectname
    => Continue
    => Register
    => Done
 
Step 7:
 To developer.apple.com
 ISO,tvOS, watchOS
  Devices
   All
    => click +
    => Name -> iPad name
    => UUID -> iPad UUID Code
   iPad UUID Code可以在 Xcode Devices 中查得
 
 
Step 8:
 To developer.apple.com
 ISO,tvOS, watchOS
  Provisioning Profiles
   All
    => click +
    => Development
       Click "IOS App development"
    => Continue
    => Select App IDs -> tw.com.mydomain.myprojectname
    => Continue
    => Select All -> xxxx (iOS Development)
    => Continue
    => Select All -> iPad name
    => Continue
    => Profile Name -> iOS_development_mydomain_myprojectname
    => Continue
    => Download
       File save -> iOS_development_mydomain_myprojectname.mobileprovision
    => Done
   
Step 9:
 To developer.apple.com
 ISO,tvOS, watchOS
  Provisioning Profiles
   All
    => click +
    => Distrbution
       Click "App Stroe"
    => Continue
    => Select App IDs -> tw.com.mydomain.myprojectname
    => Continue
    => Select xxxx (iOS Distrbution)
    => Continue
    => Profile Name -> iOS_Distrbution_AppStore_mydomain_myprojectname
    => Continue
    => Download
       File save -> iOS_Distrbution_AppStore__mydomain_myprojectname.mobileprovision
    => Done
   
Step 10:
 To developer.apple.com
 ISO,tvOS, watchOS
  Provisioning Profiles
   All
    => click +
    => Distrbution
       Click "Ad Hoc"
    => Continue
    => Select App IDs -> tw.com.mydomain.myprojectname
    => Continue
    => Select xxxx (iOS Distrbution)
    => Continue
    => Select All -> iPad name
    => Continue
    => Profile Name -> iOS_Distrbution_AdHoc_mydomain_myprojectname
    => Continue
    => Download
       File save -> iOS_Distrbution_AdHoc_mydomain_myprojectname.mobileprovision
    => Done
 //==========================================================
問題: 無法登入  Xcode -> Open Developer Tools  ->  Application Loader

登入 https://appleid.apple.com/account/manage
點選 App 專用密碼 產生密碼⋯

重新進入 Application Loader
使用Apple ID 配合用這組產生的密碼登入



 //==========================================================