Ejemplo n.º 1
0
        public override void DidEnterBackground(UIApplication application)
        {
            var       subViews = mapViewController.View.Subviews;
            MKMapView mapView  = subViews[0] as MKMapView;

            Console.WriteLine("mapView: {0}", mapView);
            var            tempArray   = mapView.Annotations;
            NSMutableArray annotations = new NSMutableArray();

            Console.WriteLine("tempArray: {0}", tempArray.ToString());
            for (int i = 0; i < tempArray.Length; i++)
            {
                if (tempArray[i].GetType() == typeof(MKUserLocation))
                {
                    Console.WriteLine("MKUserLocation: {0}", tempArray[i]);
                }
                else
                {
                    Console.WriteLine("MKMapPoint added: {0}", tempArray[i]);
                    annotations.Add(tempArray[i]);
                }
            }
            var    documentDirectories = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User, true);
            string documentDirectory   = documentDirectories[0];
            string path = Path.Combine(documentDirectory, "annotations.archive");

            Console.WriteLine("Path: {0}", path);
            bool success = NSKeyedArchiver.ArchiveRootObjectToFile(annotations, path);

            if (success)
            {
                Console.WriteLine("Saved Annotations {0}", annotations.ToString());
            }
        }
        // NSURLConnection delegates (generally we pass these on to our client)

        public override NSUrlRequest WillSendRequest(NSUrlConnection connection, NSUrlRequest request, NSUrlResponse response)
        {
            // Thanks to Nick Dowell https://gist.github.com/1885821
            if (response != null)
            {
                var redirectableRequest = Request.MutableCopy as NSMutableUrlRequest;

                // We need to remove our header so we know to handle this request and cache it.
                // There are 3 requests in flight: the outside request, which we handled, the internal request,
                // which we marked with our header, and the redirectableRequest, which we're modifying here.
                // The redirectable request will cause a new outside request from the NSURLProtocolClient, which
                // must not be marked with our header.
                redirectableRequest.SetValueForKey(null, MtRnCachingUrlHeader);

                var cachePath = CachePathForRequest(this.Request);
                var cache     = new MtRnCachedData();
                cache.Response        = response;
                cache.Data            = this.Data;
                cache.RedirectRequest = redirectableRequest;
                NSKeyedArchiver.ArchiveRootObjectToFile(cache, cachePath);
                this.Client.Redirected(this, redirectableRequest, response);
                return(redirectableRequest);
            }
            else
            {
                return(request);
            }
        }
        public override void FinishedLoading(NSUrlConnection connection)
        {
            Client.FinishedLoading(this);

            var cachePath = CachePathForRequest(this.Request);
            var cache     = new MtRnCachedData();

            cache.Response = this.Response;
            cache.Data     = this.Data;
            NSKeyedArchiver.ArchiveRootObjectToFile(cache, cachePath);

            Connection = null;
            Data       = null;
            Response   = null;
        }
Ejemplo n.º 4
0
 public void StoreValues()
 {
     NSKeyedArchiver.ArchiveRootObjectToFile(this, archiveLocation);
 }
Ejemplo n.º 5
0
 public void ArchiveText(string filename, string text)
 {
     NSKeyedArchiver.ArchiveRootObjectToFile(NSObject.FromObject(text), GetFilePath(filename));
 }