public void OnMessageReceived(NSDictionary userInfo) { var parameters = new Dictionary<string, object>(); foreach (NSString key in userInfo.Keys) { if(key == "aps") { NSDictionary aps = userInfo.ValueForKey(key) as NSDictionary; if(aps != null) { foreach(var apsKey in aps) parameters.Add(apsKey.Key.ToString(), apsKey.Value); } } parameters.Add(key, userInfo.ValueForKey(key)); } if (CrossPushNotification.IsInitialized) { CrossPushNotification.PushNotificationListener.OnMessage(parameters, DeviceType.iOS); }else { throw NewPushNotificationNotInitializedException(); } }
public void OnMessageReceived(NSDictionary userInfo) { var parameters = new Dictionary<string, object>(); foreach (NSString key in userInfo.Keys) { if(key == "aps") { // flatten this dictionary for the handler var apsDict = userInfo.ValueForKey(key) as NSDictionary; if(apsDict != null) { foreach(var apsKey in apsDict) parameters.Add(apsKey.Key.ToString(), apsKey.Value); } } parameters.Add(key, userInfo.ValueForKey(key)); } Debug.WriteLine("OnMessageReceived keys: "); foreach(var item in parameters) Debug.WriteLine(" {0} = {1}", item.Key, item.Value); if (CrossPushNotification.IsInitialized) { CrossPushNotification.PushNotificationListener.OnMessage(parameters, DeviceType.iOS); }else { throw NewPushNotificationNotInitializedException(); } }
public override bool FinishedLaunching( UIApplication application, NSDictionary launchOptions ) { // Override point for customization after application launch. // If not required for your application you can safely delete this method if ( launchOptions != null && launchOptions.ValueForKey( UIApplication.LaunchOptionsLocationKey ) != null ) { Console.WriteLine( "JERED: Launched from region entered while terminated" ); } else { Console.WriteLine( "JERED: *NOT* launched due to region monitoring." ); } // ask to send notifications var settings = UIUserNotificationSettings.GetSettingsForTypes( UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, new NSSet()); UIApplication.SharedApplication.RegisterUserNotificationSettings(settings); // setup our window Window = new UIWindow( UIScreen.MainScreen.Bounds ); MainController = new ViewController(); MainController.View.Bounds = Window.Bounds; Window.RootViewController = MainController; Window.MakeKeyAndVisible( ); SharedCode.LocationLayer.Create( null ); return true; }
public async Task RaiseCallbackAsync(NSDictionary callbackInfo) { ScheduledCallback callback = TryGetCallback(callbackInfo); string invocationId = callbackInfo?.ValueForKey(new NSString(SENSUS_CALLBACK_INVOCATION_ID_KEY)) as NSString; await RaiseCallbackAsync(callback, invocationId); }
public void OnMessageReceived(NSDictionary userInfo) { var parameters = new Dictionary<string, object>(); var json = DictionaryToJson(userInfo); JObject values = JObject.Parse(json); var keyAps = new NSString("aps"); if (userInfo.ContainsKey(keyAps)) { NSDictionary aps = userInfo.ValueForKey(keyAps) as NSDictionary; if (aps != null) { foreach (var apsKey in aps) { parameters.Add(apsKey.Key.ToString(), apsKey.Value); JToken temp; if (!values.TryGetValue(apsKey.Key.ToString(), out temp)) values.Add(apsKey.Key.ToString(), apsKey.Value.ToString()); } } } CrossPushNotification.PushNotificationListener.OnMessage(values, DeviceType.iOS); }
public void OpenDisplayPage(NSDictionary notificationInfo) { DisplayPage displayPage; if (Enum.TryParse(notificationInfo?.ValueForKey(new NSString(Notifier.DISPLAY_PAGE_KEY)) as NSString, out displayPage)) { SensusContext.Current.Notifier.OpenDisplayPage(displayPage); } }
public Task ServiceCallbackAsync(NSDictionary callbackInfo) { return(Task.Run(async() => { // check whether the passed information describes a callback NSNumber isCallback = callbackInfo?.ValueForKey(new NSString(SENSUS_CALLBACK_KEY)) as NSNumber; if (!(isCallback?.BoolValue ?? false)) { return; } // not sure why the following would be null, but we've seen NRE in insights and these are the likely suspects. string callbackId = (callbackInfo.ValueForKey(new NSString(iOSNotifier.NOTIFICATION_ID_KEY)) as NSString)?.ToString(); bool repeating = (callbackInfo.ValueForKey(new NSString(SENSUS_CALLBACK_REPEATING_KEY)) as NSNumber)?.BoolValue ?? false; TimeSpan repeatDelay = TimeSpan.Zero; if (repeating) { repeatDelay = TimeSpan.FromTicks(long.Parse(callbackInfo.ValueForKey(new NSString(SENSUS_CALLBACK_REPEAT_DELAY_KEY)) as NSString)); } bool repeatLag = (callbackInfo.ValueForKey(new NSString(SENSUS_CALLBACK_REPEAT_LAG_KEY)) as NSNumber)?.BoolValue ?? false; // only raise callback if it is still scheduled if (!CallbackIsScheduled(callbackId)) { return; } SensusServiceHelper.Get().Logger.Log("Servicing callback " + callbackId, LoggingLevel.Normal, GetType()); // start background task nint callbackTaskId = -1; SensusContext.Current.MainThreadSynchronizer.ExecuteThreadSafe(() => { callbackTaskId = UIApplication.SharedApplication.BeginBackgroundTask(() => { // if we're out of time running in the background, cancel the callback. CancelRaisedCallback(callbackId); }); }); // raise callback but don't notify user since we would have already done so when the notification was delivered to the notification tray. // we don't need to specify how repeats will be scheduled, since the class that extends this one will take care of it. furthermore, there's // nothing to do if the callback thinks we can sleep, since ios does not provide wake-locks like android. await RaiseCallbackAsync(callbackId, repeating, repeatDelay, repeatLag, false, null, null); SensusContext.Current.MainThreadSynchronizer.ExecuteThreadSafe(() => { UIApplication.SharedApplication.EndBackgroundTask(callbackTaskId); }); })); }
public void ServiceCallbackAsync(NSDictionary callbackInfo) { // check whether the passed information describes a callback NSNumber isCallback = callbackInfo?.ValueForKey(new NSString(SENSUS_CALLBACK_KEY)) as NSNumber; if (!(isCallback?.BoolValue ?? false)) { return; } // not sure why the following would be null, but we've seen NRE in insights and these are the likely suspects. string callbackId = (callbackInfo.ValueForKey(new NSString(Notifier.NOTIFICATION_ID_KEY)) as NSString)?.ToString(); bool repeating = (callbackInfo.ValueForKey(new NSString(SENSUS_CALLBACK_REPEATING_KEY)) as NSNumber)?.BoolValue ?? false; int repeatDelayMS = (callbackInfo.ValueForKey(new NSString(SENSUS_CALLBACK_REPEAT_DELAY_KEY)) as NSNumber)?.Int32Value ?? 100000; // not sure what the right value is here. bool repeatLag = (callbackInfo.ValueForKey(new NSString(SENSUS_CALLBACK_REPEAT_LAG_KEY)) as NSNumber)?.BoolValue ?? false; // only raise callback if it is still scheduled if (!CallbackIsScheduled(callbackId)) { return; } // start background task nint callbackTaskId = -1; SensusContext.Current.MainThreadSynchronizer.ExecuteThreadSafe(() => { callbackTaskId = UIApplication.SharedApplication.BeginBackgroundTask(() => { // if we're out of time running in the background, cancel the callback. CancelRaisedCallback(callbackId); }); }); // raise callback but don't notify user since we would have already done so when the notification was delivered to the notification tray. RaiseCallbackAsync(callbackId, repeating, repeatDelayMS, repeatLag, false, // don't need to specify how repeats will be scheduled. the class that extends this one will take care of it. null, // nothing to do if the callback thinks we can sleep. ios does not provide wake-locks like android. null, // we've completed the raising process, so end background task () => { SensusContext.Current.MainThreadSynchronizer.ExecuteThreadSafe(() => { UIApplication.SharedApplication.EndBackgroundTask(callbackTaskId); }); }); }
//UITabBarController TabController; // // This method is invoked when the application has loaded and is ready to run. In this // method you should instantiate the window, load the UI into it and then make the window // visible. // You have 17 seconds to return from this method, or iOS will terminate your application. // public static void RegisterDefaultsFromSettingsBundle() { string settingsBundle = NSBundle.MainBundle.PathForResource("Settings", @"bundle"); if(settingsBundle == null) { System.Console.WriteLine(@"Could not find Settings.bundle"); return; } NSString keyString = new NSString(@"Key"); NSString defaultString = new NSString(@"DefaultValue"); NSDictionary settings = NSDictionary.FromFile(Path.Combine(settingsBundle,@"Root.plist")); NSArray preferences = (NSArray) settings.ValueForKey(new NSString(@"PreferenceSpecifiers")); NSMutableDictionary defaultsToRegister = new NSMutableDictionary(); for (uint i=0; i<preferences.Count; i++) { NSDictionary prefSpecification = new NSDictionary(preferences.ValueAt(i)); NSString key = (NSString) prefSpecification.ValueForKey(keyString); if(key != null) { NSObject def = prefSpecification.ValueForKey(defaultString); if (def != null) { defaultsToRegister.SetValueForKey(def, key); } } } NSUserDefaults.StandardUserDefaults.RegisterDefaults(defaultsToRegister); }
public override bool FinishedLaunching(UIApplication app, NSDictionary options) { PushNotificationManager pushmanager = PushNotificationManager.PushManager; pushmanager.Delegate = this; if (options != null) { if (options.ContainsKey (UIApplication.LaunchOptionsRemoteNotificationKey)) { var data = (NSDictionary)options.ValueForKey (UIApplication.LaunchOptionsRemoteNotificationKey); HandleRemoteNotification (data, true); } } return true; }
public void OnMessageReceived(NSDictionary userInfo) { var parameters = new Dictionary<string, object>(); foreach (NSString key in userInfo.Keys) { parameters.Add(key, userInfo.ValueForKey(key)); } if (CrossPushNotification.IsInitialized) { CrossPushNotification.PushNotificationListener.OnMessage(parameters, DeviceType.iOS); }else { throw NewPushNotificationNotInitializedException(); } }
public override void ViewDidLoad () { base.ViewDidLoad (); controls = new NSMutableArray (); // Fetching data from plist files string controlListPathString = NSBundle.MainBundle.BundlePath+"/ControlList.plist"; controlDict = new NSDictionary(); controlDict = NSDictionary.FromFile(controlListPathString); NSString controlDictKey = new NSString ("Control"); controlDictArray = controlDict.ValueForKey (controlDictKey) as NSArray; this.PrepareControlList (); // Register the TableView's data source TableView.Source = new AllControlsViewSource (this); }
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler) { NSObject apsValue=userInfo.ValueForKey(new NSString("aps")); NSObject alertValue=apsValue.ValueForKey(new NSString("alert")); string msg=((NSString)alertValue).ToString(); UIAlertController Alert = UIAlertController.Create ("", msg, UIAlertControllerStyle.Alert); Alert.AddAction (UIAlertAction.Create ("OK", UIAlertActionStyle.Cancel, null)); try{ if(Global.tabBarController!=null){ Global.tabBarController.PresentViewController(Alert,true,null); }else{ Window.RootViewController.PresentViewController (Alert, true, null); } }catch { //do nothing } }
void Save (string path, int size, Action<bool> callback, NSDictionary data) { bool result = false; UIImage photo = null; UIImage source = null; NSData file = null; NSError error = null; try { source = data.ValueForKey (new NSString ("UIImagePickerControllerOriginalImage")) as UIImage; if (source != null) { photo = ScaleImage (source, size); file = photo.AsJPEG (); error = null; bool saved = file.Save (path, false, out error); if (!saved) _context.HandleException (new NonFatalException (D.IO_EXCEPTION, error.LocalizedDescription)); result = saved; } } finally { if (photo != null) photo.Dispose (); if (source != null) source.Dispose (); if (file != null) file.Dispose (); if (error != null) error.Dispose (); } Task.Run (() => { Thread.Sleep (300); _context.InvokeOnMainThread (() => callback (result)); }); }
public static bool IsCallback(NSDictionary callbackInfo) { NSNumber isCallback = callbackInfo?.ValueForKey(new NSString(SENSUS_CALLBACK_KEY)) as NSNumber; return(isCallback?.BoolValue ?? false); }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); this.NavigationController.NavigationBar.BarTintColor = Utility.ThemeColor; this.View.BackgroundColor = UIColor.White; menuButton = new UIBarButtonItem { Image = UIImage.FromBundle("Images/Changefile"), Style = UIBarButtonItemStyle.Plain, Target = this }; menuButton.Clicked += OpenMenu; fadeOutView = new UIView(this.View.Bounds) { BackgroundColor = UIColor.FromRGBA(0.537f, 0.537f, 0.537f, 0.3f) }; UITapGestureRecognizer singleFingerTap = new UITapGestureRecognizer(); singleFingerTap.AddTarget(() => HandleSingleTap(singleFingerTap)); fadeOutView.AddGestureRecognizer(singleFingerTap); string controlListPathString = NSBundle.MainBundle.BundlePath + "/plist/SourceList.plist"; NSDictionary controlDict = new NSDictionary(); controlDict = NSDictionary.FromFile(controlListPathString); NSString controlDictKey = new NSString(ControlName); string sample = GetFileName(SampleName); NSDictionary controlDictArray = controlDict.ValueForKey(controlDictKey) as NSDictionary; if (controlDictArray != null) { NSString sampleDictKey = new NSString(sample); SampleDictionaryArray = controlDictArray.ValueForKey(sampleDictKey) as NSArray; if (SampleDictionaryArray != null) { sample = (string)SampleDictionaryArray.GetItem <NSString>(0); this.NavigationItem.SetRightBarButtonItem(menuButton, true); menuVisible = false; nfloat height = this.View.Bounds.Height - 64; nfloat left = this.View.Bounds.Width - 260; MenuView = new UIView(new CGRect(left, 64, 260, height)); MenuTable = new UITableView(new CGRect(0, 0, 260, height)); MenuTable.Layer.BorderWidth = 0.5f; MenuTable.Layer.BorderColor = UIColor.FromRGBA(0.537f, 0.537f, 0.537f, 0.5f).CGColor; MenuTable.BackgroundColor = UIColor.White; MenuTable.Source = new SampleDataSource(this); NSIndexPath indexPath = NSIndexPath.FromRowSection(0, 0); MenuTable.SelectRow(indexPath, false, UITableViewScrollPosition.Top); MenuView.AddSubview(MenuTable); } } viewer = new UILabel { Font = UIFont.SystemFontOfSize(12.0f), Lines = 0, LineBreakMode = UILineBreakMode.WordWrap }; viewer.SizeToFit(); scrollview = new UIScrollView(); scrollview.AddSubview(viewer); this.View.AddSubview(scrollview); this.LoadSample((string)sample); }
public override void DiscoveredPeripheral(CBCentralManager central, CBPeripheral peripheral, NSDictionary advertisementData, NSNumber RSSI) { if (advertisementData.ContainsKey(CBAdvertisement.DataServiceDataKey)) { var tmp = advertisementData.ObjectForKey(CBAdvertisement.DataManufacturerDataKey); var serviceData = advertisementData.ValueForKey(CBAdvertisement.DataServiceDataKey) as NSDictionary; var eft = BeaconInfo.FrameTypeForFrame(serviceData); if (eft == EddystoneFrameType.TelemetryFrameType) { if (!_deviceIDCache.ContainsKey(peripheral.Identifier)) { _deviceIDCache.Add(peripheral.Identifier, BeaconInfo.TelemetryDataForFrame(serviceData)); } } else if (eft == EddystoneFrameType.UIDFrameType || eft == EddystoneFrameType.EIDFrameType) { if (peripheral.Identifier != null && _deviceIDCache.ContainsKey(peripheral.Identifier)) { var telemetry = _deviceIDCache[peripheral.Identifier]; var rssi = RSSI.Int32Value; var beaconInfo = (eft == EddystoneFrameType.UIDFrameType ? BeaconInfo.BeaconInfoForUIDFrameData(serviceData, telemetry, rssi) : BeaconInfo.BeaconInfoForEIDFrameData(serviceData, telemetry, rssi)); if (beaconInfo != null) { _deviceIDCache.Remove(peripheral.Identifier); if (_seenEddystoneCache.ContainsKey(new NSString(beaconInfo.BeaconID.Description))) { var timer = _seenEddystoneCache.ObjectForKey(new NSString(beaconInfo.BeaconID.Description + "_onLostTimer")) as NSTimer; timer.Invalidate(); timer = NSTimer.CreateScheduledTimer(_onLostTimeout, t => { var cacheKey = beaconInfo.BeaconID.Description; if (_seenEddystoneCache.ContainsKey(new NSString(cacheKey))) { var lostBeaconInfo = _seenEddystoneCache.ObjectForKey(new NSString(cacheKey)) as BeaconInfo; if (lostBeaconInfo != null) { _seenEddystoneCache.Remove(new NSString(beaconInfo.BeaconID.Description)); _seenEddystoneCache.Remove(new NSString(beaconInfo.BeaconID.Description + "_onLostTimer")); DidLoseBeacon(lostBeaconInfo); } } }); DidUpdateBeacon(beaconInfo); } else { DidFindBeacon(beaconInfo); var timer = NSTimer.CreateScheduledTimer(_onLostTimeout, t => { var cacheKey = beaconInfo.BeaconID.Description; if (_seenEddystoneCache.ContainsKey(new NSString(cacheKey))) { var lostBeaconInfo = _seenEddystoneCache.ObjectForKey(new NSString(cacheKey)) as BeaconInfo; if (lostBeaconInfo != null) { _seenEddystoneCache.Remove(new NSString(beaconInfo.BeaconID.Description)); _seenEddystoneCache.Remove(new NSString(beaconInfo.BeaconID.Description + "_onLostTimer")); DidLoseBeacon(lostBeaconInfo); } } }); _seenEddystoneCache.SetValueForKey(beaconInfo, new NSString(beaconInfo.BeaconID.Description)); _seenEddystoneCache.SetValueForKey(timer, new NSString(beaconInfo.BeaconID.Description + "_onLostTimer")); } } } } else if (eft == EddystoneFrameType.URLFrameType) { var rssi = RSSI.Int32Value; var url = BeaconInfo.ParseUrlFromFrame(serviceData); var name = peripheral.Name; var services = peripheral.Services; DidObserveURLBeacon(url, rssi); } else { MvxTrace.TaggedTrace(MvxTraceLevel.Diagnostic, "Beacons", "Unable to find service data; can't process Eddystone"); } } else { } }
public override void RowSelected (UITableView tableView, NSIndexPath indexPath) { nuint row = (nuint)indexPath.Row; Control ctrl = controls.GetItem<Control> (row); string sampleListPathString = NSBundle.MainBundle.BundlePath+"/SampleList.plist"; sampleDict = new NSDictionary(); sampleDict = NSDictionary.FromFile(sampleListPathString); NSMutableArray dictArray = sampleDict.ValueForKey (new NSString (ctrl.name)) as NSMutableArray; NSMutableArray sampArray = new NSMutableArray (); for (nuint i = 0; i < dictArray.Count; i++) { NSDictionary dict = dictArray.GetItem<NSDictionary> (i); sampArray.Add(dict.ValueForKey( new NSString("SampleName"))); } SampleViewController sampleController = new SampleViewController(); sampleController.selectedControl = ctrl.name; sampleController.sampleDictionaryArray = dictArray; sampleController.sampleArray = sampArray; controller.NavigationController.PushViewController(sampleController,true); }
/// <summary> /// Obtengo ciudad de SQLite o del servidor. /// </summary> public void GetDataCiudad() { // Ciudad Ciudad c; // Obtengo ciudad c = SQLiteManager.Connection().GetCiudad(ID_Ciudad); // Compruebo datos if (c == null) { // Obtengo ciudad del servidor RestManager.Connection().GetData((int)URIS.GetCiudad, new string[] { ID_Ciudad.ToString() }, null, (arg) => { // Compruebo datos if (!string.IsNullOrWhiteSpace(arg)) { // Deserializo JSON NSDictionary data = (NSDictionary)NSJsonSerialization.Deserialize(arg, 0, out NSError e); // Leo datos foreach (NSString key in data.Keys) { switch (key.ToString().ToLower()) { case "id_ciudad": ID_Ciudad = (int)(NSNumber)data.ValueForKey(key); break; case "id_provincia": ID_Provincia = (int)(NSNumber)data.ValueForKey(key); break; case "nombre": Nombre_Ciudad = data.ValueForKey(key).ToString(); break; } } // Guardo en SQLite SQLiteManager.Connection().SetCiudad(this); } // Continuo lock (l) { Monitor.Pulse(l); } }); // Espero lock (l) { Monitor.Wait(l); } } else { // Cargo nombre Nombre_Ciudad = c.Nombre_Ciudad; // Cargo ID provincia ID_Provincia = c.ID_Provincia; } // Obtengo datos provincia GetDataProvincia(); }
public static async Task Fetch() { AppData.invitationsLST = new List <ChatListClass>(); if (AppData.auth.CurrentUser == null) { return; } bool done = false; foreach (InvitationClass anyCoord in AppData.invitationsData) { string chatName = anyCoord.ChatName; string ownerUid = anyCoord.ChatOwner.Uid; AppData.DataNode.GetChild(ownerUid).GetChild(chatName).ObserveSingleEvent(DataEventType.Value, (snapshot) => { var thisChatAllData = snapshot.GetValue <NSDictionary>(); List <MessageClass> itemsInChat = new List <MessageClass>(); if (thisChatAllData.ValueForKey((NSString)"items") != null) { if ((thisChatAllData.ValueForKey((NSString)"items")).IsKindOfClass(new ObjCRuntime.Class(typeof(NSDictionary)))) { NSDictionary itemsOfChatVals = (NSDictionary)NSObject.FromObject(thisChatAllData.ValueForKey((NSString)"items")); for (int i = 0; i < (int)itemsOfChatVals.Values.Length; i++) { NSDictionary eachItemVals = (NSDictionary)NSObject.FromObject(itemsOfChatVals.Values[i]); var fetchedItemName = (NSString)eachItemVals.ValueForKey((NSString)"itemName"); var fetchedItemCategory = (NSString)eachItemVals.ValueForKey((NSString)"itemCategory"); var fetchedItemTime = (NSString)eachItemVals.ValueForKey((NSString)"itemTime"); itemsInChat.Add(new MessageClass { ItemName = fetchedItemName, ItemTime = DateTime.Parse(fetchedItemTime) }); } } } ChatListClass thisChat = new ChatListClass { ChatName = chatName, ChatOwner = anyCoord.ChatOwner, ChatItems = itemsInChat }; AppData.invitationsLST.Add(thisChat); done = true; }); } while (!done) { await Task.Delay(50); } }
private void ParseControlsPlist() { string controlListPathString = NSBundle.MainBundle.BundlePath + "/plist/ControlList.plist"; NSDictionary controlDict = new NSDictionary(); controlDict = NSDictionary.FromFile(controlListPathString); NSString controlDictKey = new NSString("Control"); NSArray controlDictArray = controlDict.ValueForKey(controlDictKey) as NSArray; Controls = new NSMutableArray(); if (controlDictArray.Count > 0) { for (nuint i = 0; i < controlDictArray.Count; i++) { NSDictionary dict = controlDictArray.GetItem <NSDictionary>(i); string image = dict.ValueForKey(new NSString("ControlName")).ToString(); image = "Controls/" + image; Control control = new Control { Name = new NSString(dict.ValueForKey(new NSString("ControlName")).ToString()), Description = new NSString(dict.ValueForKey(new NSString("Description")).ToString()), Image = UIImage.FromBundle(image) }; if (!UIDevice.CurrentDevice.CheckSystemVersion(9, 0) && control.Name == "PDFViewer") { continue; } if (dict.ValueForKey(new NSString("IsNew")) != null && dict.ValueForKey(new NSString("IsNew")).ToString() == "YES") { control.Tag = new NSString("NEW"); } else if (dict.ValueForKey(new NSString("IsUpdated")) != null && dict.ValueForKey(new NSString("IsUpdated")).ToString() == "YES") { control.Tag = new NSString("UPDATED"); } else if (dict.ValueForKey(new NSString("IsPreview")) != null && dict.ValueForKey(new NSString("IsPreview")).ToString() == "YES") { control.Tag = new NSString("PREVIEW"); } else { control.Tag = new NSString(string.Empty); } if (dict.ValueForKey(new NSString("Type1")) != null) { control.IsMultipleSampleView = true; control.Type1 = new NSString(dict.ValueForKey(new NSString("Type1")).ToString()); control.Type2 = new NSString(dict.ValueForKey(new NSString("Type2")).ToString()); } Controls.Add(control); } } }
public static bool GetBoolForKey(this NSDictionary dict, string key, bool defaultValue) { var value = dict.ValueForKey(new NSString(key)); return(value == null ? defaultValue : (value as NSNumber).BoolValue); }
public static long?GetLongForKey(this NSDictionary dict, string key) { var value = dict.ValueForKey(new NSString(key)); return(value == null ? null as long? : (value as NSNumber).LongValue); }
public static long GetLongForKey(this NSDictionary dict, string key, long defaultValue) { var value = dict.ValueForKey(new NSString(key)); return(value == null ? defaultValue : (value as NSNumber).LongValue); }
public static bool?GetBoolForKey(this NSDictionary dict, string key) { var value = dict.ValueForKey(new NSString(key)); return(value == null ? null as bool? : (value as NSNumber).BoolValue); }
public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo) { // show an alert var body = userInfo.ValueForKey (new NSString("inAppMessage")).ToString (); var alert = MBAlertView.AlertWithBody (body, "Ok", null); alert.AddToDisplayQueue (); // new UIAlertView("Back Channel Word Alert", userInfo.ValueForKey("inAppMessage").ToString(), null, "OK", null).Show(); // reset our badge UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0; }
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath) { var cell = tableView.DequeueReusableCell (SampleTableViewCell.Key) as SampleTableViewCell; if (cell == null) cell = new SampleTableViewCell (); // Configure the cell... nuint row = (nuint)indexPath.Row; NSString sampleName = sampleArray.GetItem<NSString> (row); cell.TextLabel.Text = sampleName; sampleDict = sampleDictArray.GetItem<NSDictionary>(row); if (sampleDict.ValueForKey (new NSString ("SampleName")).ToString () == sampleName) { if (sampleDict.ValueForKey (new NSString ("IsNew")).ToString () == "YES") { cell.DetailTextLabel.Text = "NEW"; cell.DetailTextLabel.TextColor = UIColor.FromRGB (148, 75, 157); } else if (sampleDict.ValueForKey (new NSString ("IsUpdated")).ToString () == "YES") { cell.DetailTextLabel.Text = "UPDATED"; cell.DetailTextLabel.TextColor = UIColor.FromRGB (148, 75, 157); } else { cell.DetailTextLabel.Text = null; } } cell.Accessory = UITableViewCellAccessory.None; return cell; }
private void inspect (NSArray selectedObjects) { NSDictionary objectDict = new NSDictionary (selectedObjects.ValueAt (0)); if (objectDict != null) { NSString sss = new NSString ("url"); NSUrl url = new NSUrl (objectDict.ValueForKey (sss).ToString ()); NSWorkspace.SharedWorkspace.OpenUrl (url); } }
public static string GetStringForKey(this NSDictionary dict, string key, string defaultValue = null) { var value = dict.ValueForKey(new NSString(key)); return(value == null ? defaultValue : (value as NSString).ToString()); }
public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath) { nuint row = (nuint)indexPath.Row; Control ctrl = Controller.Controls.GetItem <Control>(row); string sampleListPathString = NSBundle.MainBundle.BundlePath + "/plist/SampleList.plist"; NSDictionary sampleDict = new NSDictionary(); sampleDict = NSDictionary.FromFile(sampleListPathString); NSMutableArray dictArray = sampleDict.ValueForKey(new NSString(ctrl.Name)) as NSMutableArray; NSMutableArray collections = new NSMutableArray(); Control contrl = Controller.Controls.GetItem <Control>((nuint)indexPath.Row); for (nuint i = 0; i < dictArray.Count; i++) { NSDictionary dict = dictArray.GetItem <NSDictionary>(i); Control control = new Control { ControlName = ctrl.Name, Name = (NSString)dict.ValueForKey(new NSString("SampleName")), Description = (NSString)dict.ValueForKey(new NSString("Description")) }; NSString imageToLoad = (NSString)dict.ValueForKey(new NSString("Image")); if (imageToLoad != null) { control.Image = UIImage.FromBundle(imageToLoad); } if (dict.ValueForKey(new NSString("IsNew")) != null && dict.ValueForKey(new NSString("IsNew")).ToString() == "YES") { control.Tag = new NSString("NEW"); } else if (dict.ValueForKey(new NSString("IsUpdated")) != null && dict.ValueForKey(new NSString("IsUpdated")).ToString() == "YES") { control.Tag = new NSString("UPDATED"); } else if (dict.ValueForKey(new NSString("IsPreview")) != null && dict.ValueForKey(new NSString("IsPreview")).ToString() == "YES") { control.Tag = new NSString("PREVIEW"); } else { control.Tag = new NSString(string.Empty); } if (dict.ValueForKey(new NSString("DisplayName")) != null) { control.DisplayName = dict.ValueForKey(new NSString("DisplayName")) as NSString; } else { control.DisplayName = new NSString(string.Empty); } collections.Add(control); } this.Controller.NavigationItem.BackBarButtonItem = new UIBarButtonItem("Back", UIBarButtonItemStyle.Plain, null); if (ctrl.Name == "Chart") { ChartSamplesViewController sampleController = new ChartSamplesViewController { FeaturesCollections = collections, ControlName = contrl.Name, Types = contrl.Type1, Features = contrl.Type2 }; Controller.NavigationController.PushViewController(sampleController, true); } else { indexPath = NSIndexPath.FromRowSection(0, 0); SampleViewController controller = new SampleViewController(indexPath) { SamplesCollection = collections, ControlName = contrl.Name }; Controller.NavigationController.PushViewController(controller, true); } }
static FileResult DictionaryToMediaFile(NSDictionary info) { if (info == null) { return(null); } PHAsset phAsset = null; NSUrl assetUrl = null; if (Platform.HasOSVersion(11, 0)) { assetUrl = info[UIImagePickerController.ImageUrl] as NSUrl; // Try the MediaURL sometimes used for videos if (assetUrl == null) { assetUrl = info[UIImagePickerController.MediaURL] as NSUrl; } if (assetUrl != null) { if (!assetUrl.Scheme.Equals("assets-library", StringComparison.InvariantCultureIgnoreCase)) { return(new UIDocumentFileResult(assetUrl)); } phAsset = info.ValueForKey(UIImagePickerController.PHAsset) as PHAsset; } } #if !MACCATALYST if (phAsset == null) { assetUrl = info[UIImagePickerController.ReferenceUrl] as NSUrl; if (assetUrl != null) { phAsset = PHAsset.FetchAssets(new NSUrl[] { assetUrl }, null)?.LastObject as PHAsset; } } #endif if (phAsset == null || assetUrl == null) { var img = info.ValueForKey(UIImagePickerController.OriginalImage) as UIImage; if (img != null) { return(new UIImageFileResult(img)); } } if (phAsset == null || assetUrl == null) { return(null); } string originalFilename; if (Platform.HasOSVersion(9, 0)) { originalFilename = PHAssetResource.GetAssetResources(phAsset).FirstOrDefault()?.OriginalFilename; } else { originalFilename = phAsset.ValueForKey(new NSString("filename")) as NSString; } return(new PHAssetFileResult(assetUrl, phAsset, originalFilename)); }
public static bool IsSilent(NSDictionary notificationInfo) { return((notificationInfo?.ValueForKey(new NSString(SILENT_NOTIFICATION_KEY)) as NSNumber)?.BoolValue ?? false); }
void SaveImage(NSDictionary obj) { var picture = obj.ValueForKey(new NSString("UIImagePickerControllerOriginalImage")) as UIImage; var documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); _imagePath = System.IO.Path.Combine(documentsDirectory, "picture.jpg"); // hardcoded filename, overwritten each time //_croppedImagePath = System.IO.Path.Combine(documentsDirectory, "picture-cropped.jpg"); NSData imgData = picture.AsJPEG(); NSError err = null; if (imgData.Save(_imagePath, false, out err)) { SetCropper(); //SetPicture(_imagePath); } else { Console.WriteLine("NOT saved as " + _imagePath + " because" + err.LocalizedDescription); } }