在Xamarin.iOS專案中使用預設資料庫
在Xamarin.iOS專案中使用預設資料庫
當開發者準備好一個預設資料庫檔案後,就可以將這個資料庫檔案新增到建立的專案中了。本節將分別在 Xamarin.iOS 和 Xamarin.Android 專案中使用預設資料庫。
在 Xamarin.iOS 專案中使用
在 Xamarin.iOS 專案中使用預設資料庫的具體操作步驟如下:
( 1 )建立一個 Xamarin.iOS 專案,如 iOSSQLiteDemo 。
( 2 )將上一節中建立的 Documents.db 資料庫拖動 iOSSQLiteDemo 專案的 Resources 資料夾中。
( 3 )開啟 ViewController.cs 檔案,將 Documents.db 資料庫複製到或移動到 Documents 目錄下,程式碼如下:
using Foundation; using System; using System.IO; using UIKit; namespace iOSSQLiteDemo { public partial class ViewController : UIViewController { public ViewController (IntPtr handle) : base (handle) { } public override void ViewDidLoad () { base.ViewDidLoad (); // Perform any additional setup after loading the view, typically from a nib. var projectBundle = NSBundle.MainBundle; var resourcePath = projectBundle.PathForResource("Documents", "db"); var dirManager = NSFileManager.DefaultManager; string sqlitePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "MyDocuments.db"); Console.WriteLine("資料庫檔案目錄:{0}", sqlitePath); NSError er = new NSError(); dirManager.Copy(resourcePath, sqlitePath, out er); //複製 } public override void DidReceiveMemoryWarning () { base.DidReceiveMemoryWarning (); // Release any cached data, images, etc that aren't in use. } } }
執行程式後,會在輸出視窗輸出以下的內容:
資料庫檔案目錄: /Users/mac/Library/Developer/CoreSimulator/Devices/77752D53-9F0F-400C-89BD-A88D1EFD910C/data/Containers/Data/Application/DBD889F8-BB9A-423A-A729-E659A794B18B/Documents/MyDocuments.db
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29597077/viewspace-2212723/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- XamarinSQLite教程在Xamarin.iOS專案中定位資料庫檔案SQLiteiOS資料庫
- XamarinSQLite教程Xamarin.iOS專案中開啟資料庫檔案SQLiteiOS資料庫
- 有望在專案中接觸國產資料庫資料庫
- 在vue專案中mock資料VueMock
- 資料庫學習:在資料庫中存取檔案(轉)資料庫
- Django中更改預設資料庫為mysqlDjango資料庫MySql
- XamarinSQLite教程在Xamarin.Android專案中定位資料庫檔案SQLiteAndroid資料庫
- XamarinSQLite教程在Xamarin.Android專案中使用資料庫SQLiteAndroid資料庫
- 客快物流大資料專案(五十一):資料庫表分析 物流專案 資料庫表設計大資料資料庫
- 在ORACLE中移動資料庫檔案在(轉)Oracle資料庫
- 在ORACLE中移動資料庫檔案Oracle資料庫
- 手把手教你在Flutter專案優雅的使用ORM資料庫FlutterORM資料庫
- 在Docker中能使用資料庫嗎? | BaeldungDocker資料庫
- 在ORACLE中移動資料庫檔案(轉)Oracle資料庫
- MySQL預設資料庫之mysql庫MySql資料庫
- MySQL預設資料庫之sys庫MySql資料庫
- 專案資料庫表設計與建立模型資料庫模型
- 手把手教你在Flutter專案優雅的使用ORM資料庫(下篇)FlutterORM資料庫
- 手把手教你在Flutter專案優雅的使用ORM資料庫--下篇FlutterORM資料庫
- 在專案中如何直接使用hystrix?
- 在ASP中也能使用MYSQL資料庫(轉)MySql資料庫
- C#~非同步程式設計在專案中的使用C#非同步程式設計
- 在大型專案中,抖音集團如何“用活”資料?
- 在本地修改預設啟動的資料庫例項名資料庫
- Oracle資料庫中convert()函式,在瀚高資料庫中如何替換使用?Oracle資料庫函式
- MySQL資料庫中timediff()函式,在瀚高資料庫中如何替換使用?MySql資料庫函式
- Xamarin.iOS專案編譯提示Could not AOT the assemblyiOS編譯
- MySQL預設資料庫的作用MySql資料庫
- 主流資料庫的預設埠資料庫
- 在非 laravel 專案中使用 laravel 的特性 4: 資料庫遷移 migrationLaravel資料庫
- 在C++Builder 5中使用ADO資料庫程式設計 (轉)C++UI資料庫程式設計
- 在 React 專案中全量使用 HooksReactHook
- JWT 在專案中的實際使用JWT
- 僅使用了JDBC的專案,在啟動時不需要連線資料庫JDBC資料庫
- 在SQL Server資料庫中匯入MySQL資料庫Server資料庫MySql
- MySQL預設資料庫之 information_schema庫MySql資料庫ORM
- MySQL預設資料庫之performance_schema庫MySql資料庫ORM
- MYSQL預設有4個資料庫MySql資料庫