Chapter 9 Notes

Title: Platform Specific API Calls

Summary

SAP and PCL Sound end platform information examples.

Programming Concepts Summary

Concept

Page

Dependency

180ish

Programs

Program PlatInfoSap1

Page 181.

Concepts:

  1. Uses #if and #elif, conditional compilation directives and the three platform symbols to show platform information

Classes:

  1. IOS: UIDevice is demonstrated.

  2. Android: Build is demonstrated

  3. Windows: EasClientDeviceInformation is demonstrated.

Program PlatInfoSap2

Page 185.

Concepts:

  1. Uses SAP project with "parallel" classes - SAP project must share the same namespace as the project that is using it! NOT what is commonly done across projects.
  2. Platform projects define identical classes with platform specific implementation, but with the namespace of the PCL project accessing the methods.

Classes: Same as above.

Program DisplayPlatInfo

Page 188.

Concepts:

  1. Uses defined interface in PCL that is implemented in the platform projects with a special decoration like the following:

   1 [assembly: Dependency(typeof(DisplayPlatformInfo.iOS.PlatformInfo))]
   2 namespace DisplayPlatformInfo.Droid
   3 {
   4   public class PlatformInfo : IPlatformInfo
   5   {
   6     public string GetModel()
   7     {
   8       return String.Format("{0} {1}", Build.Manufacturer,
   9       Build.Model);
  10     }
  11     public string GetVersion()
  12     {
  13       return Build.VERSION.Release.ToString();
  14     }
  15   }
  16 }
  1. Using the code from the PCL looks like this:

   1   ...
   2   IPlatformInfo platformInfo = DependencyService.Get<IPlatformInfo>();
   3   modelLabel.Text = platformInfo.GetModel();
   4   versionLabel.Text = platformInfo.GetVersion();

Classes:

  1. Demonstrations Dependency

Program MonkeyTapWithSound

Page 191.

Concepts:

  1. Mostly this is about sound, monaural sound to be specific
  2. Pulse code modulation (PCM)
  3. Platform projects define identical classes with platform specific implementation, but with the namespace of the PCL project accessing the methods.

Classes:

  1. introduces PlatformSoundPlayer, IPlatformSoundPlayer and many more related to monaural sound production!

ManagingAndProgrammingMobileApplications/Xamarin/Chapter 9 (last edited 2016-09-26 14:46:32 by scot)