Skip to content

Latest commit

 

History

History
133 lines (107 loc) · 4.54 KB

README.md

File metadata and controls

133 lines (107 loc) · 4.54 KB

DBFileOperations (Document Previewer)

  • Download document
  • Save it to Device's special folder
  • Preview any type of document (i.e. Image, PDF, Excel, Word) without 3rd party library like Syncfusion's PdfViewerControl

Platform Support

  • iOS
  • Android

Document Types

Support Name
Image
PDF
Excel, Word
RTF, PlainText

iOS Setup

Note: I have not implemented Document picker code in this project. But it's really important, so keep below mentioned things in mind:

For picking documents we have to use

  1. UIDocumentPickerViewController in Xamarin.iOS (Native code)
  2. Xamarin.Plugin.FilePicker in Xamarin.Forms

But in both case before the Document Picker can be used you have to enable iCloud support both in your application and via Apple i.e you have to add iCould Container in you App Id.

The following steps walkthrough the process of provisioning for iCloud.

  • Create an iCloud Container.
  • Create an App ID that contains the iCloud App Service.
  • Create a Provisioning profile that includes this App ID.

Now let's dive into Setup required for Document Previwer in iOS:

✔️ Add this permissions into your Info.plist file:

<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>UIFileSharingEnabled</key>
<true/> 

✔️ Make this changes in Entitlements.plist file:

<dict>
    <key>com.apple.developer.icloud-services</key>
    <array>
        <string>CloudDocuments</string>
    </array>
    <key>com.apple.developer.icloud-container-identifiers</key>
    <array>
        <string>iCloud.com.yourcompany.yourapp</string>
    </array>
    <key>com.apple.developer.ubiquity-container-identifiers</key>
    <array/>
</dict>

With this you also have to enable this option in Entitlements.plist file:

  1. Enable iCould
  • Key-value storage
  • iCouldDocuments
  • CloudKit
  1. Enable Keychain

Android Setup

Permissions:

Permission Name Required
ReadExternalStorage
WriteExternalStorage
Internet
readonly string[] Permissions =
{
    Android.Manifest.Permission.ReadExternalStorage,
    Android.Manifest.Permission.WriteExternalStorage,
    Android.Manifest.Permission.Internet,
};
@@ For apps that target Android 5.1(API level 22) or lower, there is nothing more that needs to be done. @@
@@ Apps that will run on Android 6.0(API 23 level 23) or higher should ask Run time permission checks. @@
- Handles this Exception: Xamarin: Android: 
- System.UnauthorizedAccessException: Access to the path is denied
if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
{
    if (!(CheckPermissionGranted(Manifest.Permission.ReadExternalStorage) && !CheckPermissionGranted(Manifest.Permission.WriteExternalStorage)))
    {
       ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.ReadExternalStorage, Manifest.Permission.WriteExternalStorage }, 0);
    }
}

Bonus Idea: If you don't want to perform "Missing Compliance" process manually everytime when you add build to Testflight add this permission in Info.plist file (https://stackoverflow.com/questions/35841117/missing-compliance-in-status-when-i-add-built-for-internal-testing-in-test-fligh)

<key>ITSAppUsesNonExemptEncryption</key>
<false/>  

Further reading for iOS

Further reading for Xamarin.Forms