コード例 #1
0
        public GameModel(ImageDatabase imageDatabase, GameMode mode, Difficulty diff, bool selectedMusic, bool selectedVib, LevelManager lm, Board board)
        {
            this.imageDatabase = imageDatabase;
            gameMode           = mode;
            difficulty         = diff;
            music        = selectedMusic;
            vib          = selectedVib;
            levelManager = lm;
            this.board   = board;
            Loading      = true;

#if WINDOWS
            soundAndVibration = new SoundAndVibrationWindows();
#endif
#if ANDROID
            soundAndVibration = new SoundAndVibrationAndroid();
#endif
        }
コード例 #2
0
        //		public override void ReceivedLocalNotification (UIApplication application, UILocalNotification notification)
        //		{
        //			// show an alert
        //			UIAlertController okayAlertController = UIAlertController.Create (notification.AlertAction, notification.AlertBody, UIAlertControllerStyle.Alert);
        //			okayAlertController.AddAction (UIAlertAction.Create ("OK", UIAlertActionStyle.Default, null));
        //			_window.RootViewController.PresentViewController (okayAlertController, true, null);
        //
        //			// reset our badge
        //			UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
        //		}
        //
        //		public override void ReceivedRemoteNotification (UIApplication application, NSDictionary userInfo)
        //		{
        //			//This method gets called whenever the app is already running and receives a push notification
        //			// YOU MUST HANDLE the notifications in this case.  Apple assumes if the app is running, it takes care of everything
        //			// this includes setting the badge, playing a sound, etc.
        //			processNotification (userInfo, false);
        //		}

        // https://roycornelissen.wordpress.com/2011/05/12/push-notifications-in-ios-with-monotouch/
        void processNotification(NSDictionary options, bool fromFinishedLaunching)
        {
            //Check to see if the dictionary has the aps key.  This is the notification payload you would have sent
            if (null != options && options.ContainsKey(new NSString("aps")))
            {
                //Get the aps dictionary
                NSDictionary aps = options.ObjectForKey(new NSString("aps")) as NSDictionary;

                string alert = string.Empty;
                string sound = string.Empty;
                int    badge = -1;

                //Extract the alert text
                //NOTE: If you're using the simple alert by just specifying "  aps:{alert:"alert msg here"}  "
                //      this will work fine.  But if you're using a complex alert with Localization keys, etc., your "alert" object from the aps dictionary
                //      will be another NSDictionary... Basically the json gets dumped right into a NSDictionary, so keep that in mind
                if (aps.ContainsKey(new NSString("alert")))
                {
                    alert = (aps [new NSString("alert")] as NSString).ToString();
                }

                //Extract the sound string
                if (aps.ContainsKey(new NSString("sound")))
                {
                    sound = (aps [new NSString("sound")] as NSString).ToString();
                }

                //Extract the badge
                if (aps.ContainsKey(new NSString("badge")))
                {
                    string badgeStr = (aps [new NSString("badge")] as NSObject).ToString();
                    int.TryParse(badgeStr, out badge);
                }

                //If this came from the ReceivedRemoteNotification while the app was running,
                // we of course need to manually process things like the sound, badge, and alert.
                if (!fromFinishedLaunching)
                {
                    //Manually set the badge in case this came from a remote notification sent while the app was open
                    if (badge >= 0)
                    {
                        UIApplication.SharedApplication.ApplicationIconBadgeNumber = badge;
                    }
                    //Manually play the sound
                    if (!string.IsNullOrEmpty(sound))
                    {
                        //This assumes that in your json payload you sent the sound filename (like sound.caf)
                        // and that you've included it in your project directory as a Content Build type.
                        SoundAndVibration.PlaySound(true, sound);
                    }

                    //Manually show an alert
                    if (!string.IsNullOrEmpty(alert))
                    {
                        UIAlertView avAlert = new UIAlertView("Notification", alert, null, "OK", null);
                        avAlert.Show();
                    }
                }
            }

            //You can also get the custom key/value pairs you may have sent in your aps (outside of the aps payload in the json)
            // This could be something like the ID of a new message that a user has seen, so you'd find the ID here and then skip displaying
            // the usual screen that shows up when the app is started, and go right to viewing the message, or something like that.
            if (null != options && options.ContainsKey(new NSString("customKeyHere")))
            {
                //		launchWithCustomKeyValue = (options[new NSString("customKeyHere")] as NSString).ToString();

                //You could do something with your customData that was passed in here
            }
        }