Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System; using System.Collections.Generic; using System.Linq; using MonoTouch.Foundation; using MonoTouch.UIKit; using MonoTouch.CoreBluetooth; using MonoTouch.CoreLocation; using MonoTouch.CoreFoundation; using MonoTouch.AVFoundation; namespace FlappyMonkey.iOS { [Register ("AppDelegate")] class Program : UIApplicationDelegate { Game1 game; static readonly string uuid = "8DEEFBB9-F738-4297-8040-96668BB44281"; static readonly string uuidMinor = ""; static readonly string uuidMajor = ""; /* 1 - 4025 2 - 4016 3 - 4004 */ static readonly string beaconId = "DRCBC2014"; static CBPeripheralManager peripheralMgr; //BTPeripheralDelegate peripheralDelegate; static CLLocationManager locationMgr; static CLProximity previousProximity; static float volume = 0.5f; static float pitch = 1.0f; public override void FinishedLaunching (UIApplication app) { // Fun begins.. MonitorBeacons (); game = new Game1 (); game.Run (); } public static void MonitorBeacons() { var beaconUUID = new NSUuid (uuid); var beaconRegion = new CLBeaconRegion (beaconUUID, beaconId); beaconRegion.NotifyEntryStateOnDisplay = true; beaconRegion.NotifyOnEntry = true; beaconRegion.NotifyOnExit = true; locationMgr = new CLLocationManager (); locationMgr.RegionEntered += (object sender, CLRegionEventArgs e) => { if (e.Region.Identifier == beaconId) { UILocalNotification notification = new UILocalNotification () { AlertBody = "Digital Relativity Wuz Here" }; UIApplication.SharedApplication.PresentLocationNotificationNow (notification); } } ; locationMgr.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => { Console.WriteLine("Beacon event!"); if (e.Beacons.Length > 0) { CLBeacon beacon = e.Beacons [0]; string message = ""; switch (beacon.Proximity) { case CLProximity.Immediate: UILocalNotification notification = new UILocalNotification () { AlertBody = "Digital Relativity Wuz Here" }; UIApplication.SharedApplication.PresentLocationNotificationNow (notification); //message = "You found the beacon! Minor " + beacon.Minor.ToString(); break; case CLProximity.Near: //message = "You're getting warmer"; break; case CLProximity.Far: //message = "You're freezing cold"; break; case CLProximity.Unknown: //message = "I dunno WTF you are."; break; } if (previousProximity != beacon.Proximity) { Speak (message); } previousProximity = beacon.Proximity; } } ; locationMgr.StartMonitoring (beaconRegion); locationMgr.StartRangingBeacons (beaconRegion); } public override void ReceivedLocalNotification(UIApplication application, UILocalNotification notification) { NSUrl request = new NSUrl("http://www.digitalrelativity.com/craft-brewers-conference-2014/"); UIApplication.SharedApplication.OpenUrl(request); } public static void Speak (string text) { var speechSynthesizer = new AVSpeechSynthesizer (); // var voices = AVSpeechSynthesisVoice.GetSpeechVoices (); var speechUtterance = new AVSpeechUtterance (text) { Rate = AVSpeechUtterance.MaximumSpeechRate / 4, Voice = AVSpeechSynthesisVoice.FromLanguage ("en-AU"), Volume = volume, PitchMultiplier = pitch } ; speechSynthesizer.SpeakUtterance (speechUtterance); } /// <summary> /// The main entry point for the application. /// </summary> static void Main (string[] args) { UIApplication.Main (args, null, "AppDelegate"); } } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement