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:
- Uses #if and #elif, conditional compilation directives and the three platform symbols to show platform information
Classes:
IOS: UIDevice is demonstrated.
Android: Build is demonstrated
Windows: EasClientDeviceInformation is demonstrated.
Program PlatInfoSap2
Page 185.
Concepts:
- 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.
- 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:
- 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 }
- 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:
- Demonstrations Dependency
Program MonkeyTapWithSound
Page 191.
Concepts:
- Mostly this is about sound, monaural sound to be specific
- Pulse code modulation (PCM)
- Platform projects define identical classes with platform specific implementation, but with the namespace of the PCL project accessing the methods.
Classes:
introduces PlatformSoundPlayer, IPlatformSoundPlayer and many more related to monaural sound production!