Example #1
0
 private Boolean insertUpdateData(GcmMessage data, string path)
 {
     try {
         var db = new SQLite.SQLiteConnection (path);
         if (db.Insert (data) != 0)
             db.Update (data);
         return true;
     } catch (SQLite.SQLiteException ex) {
         Console.WriteLine ("Error inserting data ..." + ex.Message);
         return false;
     }
 }
Example #2
0
        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 alertMessage = string.Empty;

                int badge = -1;

                var docsFolder = System.Environment.GetFolderPath (System.Environment.SpecialFolder.MyDocuments);
                var pathToDatabase = System.IO.Path.Combine (docsFolder, "db_sqlnet.db");

                //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"))) {
                    alertMessage = (aps [new NSString ("alert")] as NSString).ToString ();

                    GcmMessage gcmMessage = new GcmMessage {
                        TextFrom = alertMessage,
                        TextMessage = alertMessage,
                        BundleString = alertMessage
                    };

                    //Insert data to DB
                    insertUpdateData (gcmMessage,pathToDatabase);
                }

                //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 show an alert
                    if (!string.IsNullOrEmpty (alertMessage)) {
                        UIAlertView avAlert = new UIAlertView ("Notification", alertMessage, null, "OK", null);
                        avAlert.Show ();

                    }
                } else {
                }
            }
        }
 //funciton to load data to the db
 private string insertUpdateData(GcmMessage data, string path)
 {
     try {
         var db = new SQLiteConnection (path);
         if (db.Insert (data) != 0)
             db.Update (data);
         return "Single data file inserted or updated";
     } catch (SQLiteException ex) {
         return ex.Message;
     }
 }