Ejemplo n.º 1
0
        /// <summary>
        /// PKLibrary.Replace() doesn't require user to agreee (no UI)
        /// BUT only works if the pass already exists
        /// </summary>
        void HandleReplaceTouchUpInside(object sender, EventArgs e)
        {
            if (PKPassLibrary.IsAvailable)
            {
                var documentsPath   = Environment.GetFolderPath(Environment.SpecialFolder.Personal);                // Documents folder
                var newFilePath     = Path.Combine(documentsPath, "CouponBanana2.pkpass");
                var builtInPassPath = Path.Combine(System.Environment.CurrentDirectory, "CouponBanana2.pkpass");
                if (!System.IO.File.Exists(newFilePath))
                {
                    System.IO.File.Copy(builtInPassPath, newFilePath);
                }

                NSData nsdata;
                using (FileStream oStream = File.Open(newFilePath, FileMode.Open)) {
                    nsdata = NSData.FromStream(oStream);
                }

                var err     = new NSError(new NSString("42"), -42);
                var newPass = new PKPass(nsdata, out err);

                bool alreadyExists = library.Contains(newPass);

                if (alreadyExists)
                {
                    library.Replace(newPass);
                    new UIAlertView(newPass.LocalizedDescription + " replaced!"
                                    , "your choice if you offer UI when you update", null, "OK", null).Show();
                }
                else
                {
                    new UIAlertView(newPass.LocalizedDescription + " doesn't exit"
                                    , "Can't *replace* if the pass isn't already in library", null, "OK", null).Show();
                }
            }
        }
Ejemplo n.º 2
0
 static public PKPass GetBoardingPass()
 {
     using (NSUrl url = new NSUrl(NSBundle.MainBundle.BundleUrl + "/BoardingPass.pkpass"))
         using (NSData data = NSData.FromUrl(url)) {
             NSError error;
             PKPass  pass = new PKPass(data, out error);
             Assert.Null(error, "error");
             return(pass);
         }
 }
Ejemplo n.º 3
0
 static public PKPass GetBoardingPass()
 {
     using (var url = GetBoardingPassUrl())
         using (NSData data = NSData.FromUrl(url)) {
             NSError error;
             PKPass  pass = new PKPass(data, out error);
             Assert.Null(error, "error");
             return(pass);
         }
 }
Ejemplo n.º 4
0
 void RenderPass(PKPass[] passes)
 {
     if (passes.Length == 0)
     {
         // NO PASS
         showPass.Alpha   = 0f;
         passHeading.Text = "No Event Ticket\nin Passbook";
         passImage.Image  = UIImage.FromBundle("Images/NoTicketSlash");
     }
     else
     {
         currentPass      = passes[0];
         showPass.Alpha   = 1f;
         passHeading.Text = "MonkeySpace Ticket Available";
         passImage.Image  = UIImage.FromBundle("Images/Monkey");
     }
 }
Ejemplo n.º 5
0
        public void Defaults()
        {
            TestRuntime.AssertXcodeVersion(4, 5);

            using (PKPass pass = new PKPass()) {
                Assert.Null(pass.AuthenticationToken, "AuthenticationToken");
#if !__WATCHOS__
                Assert.NotNull(pass.Icon, "Icon");
#endif
                Assert.Null(pass.LocalizedDescription, "LocalizedDescription");
                Assert.That(pass.LocalizedName, Is.EqualTo("Coupon"), "LocalizedName");
                Assert.Null(pass.OrganizationName, "OrganizationName");
                Assert.Null(pass.PassTypeIdentifier, "PassTypeIdentifier");
                Assert.Null(pass.PassUrl, "PassUrl");
                Assert.Null(pass.RelevantDate, "RelevantDate");
                Assert.Null(pass.SerialNumber, "SerialNumber");
                Assert.Null(pass.WebServiceUrl, "WebServiceUrl");
            }
        }
Ejemplo n.º 6
0
        public void Defaults()
        {
            TestRuntime.AssertXcodeVersion(4, 5);

            using (PKPass pass = new PKPass()) {
                Assert.Null(pass.AuthenticationToken, "AuthenticationToken");
#if !__WATCHOS__
#if !__MACCATALYST__ // PKPass.Icon doesn't work: https://github.com/xamarin/maccore/issues/2347
                Assert.NotNull(pass.Icon, "Icon");
#endif
#endif
                Assert.Null(pass.LocalizedDescription, "LocalizedDescription");
                Assert.That(string.IsNullOrEmpty(pass.LocalizedName), Is.False, "LocalizedName");
                Assert.Null(pass.OrganizationName, "OrganizationName");
                Assert.Null(pass.PassTypeIdentifier, "PassTypeIdentifier");
                Assert.Null(pass.PassUrl, "PassUrl");
                Assert.Null(pass.RelevantDate, "RelevantDate");
                Assert.Null(pass.SerialNumber, "SerialNumber");
                Assert.Null(pass.WebServiceUrl, "WebServiceUrl");
            }
        }
Ejemplo n.º 7
0
        public void Defaults()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(6, 0))
            {
                Assert.Inconclusive("PassKit is new in 6.0");
            }

            using (PKPass pass = new PKPass()) {
                Assert.Null(pass.AuthenticationToken, "AuthenticationToken");
#if !__WATCHOS__
                Assert.NotNull(pass.Icon, "Icon");
#endif
                Assert.Null(pass.LocalizedDescription, "LocalizedDescription");
                Assert.That(pass.LocalizedName, Is.EqualTo("Coupon"), "LocalizedName");
                Assert.Null(pass.OrganizationName, "OrganizationName");
                Assert.Null(pass.PassTypeIdentifier, "PassTypeIdentifier");
                Assert.Null(pass.PassUrl, "PassUrl");
                Assert.Null(pass.RelevantDate, "RelevantDate");
                Assert.Null(pass.SerialNumber, "SerialNumber");
                Assert.Null(pass.WebServiceUrl, "WebServiceUrl");
            }
        }
Ejemplo n.º 8
0
        void HandleAddTouchUpInside(object sender, EventArgs e)
        {
            if (PKPassLibrary.IsAvailable)
            {
                var documentsPath   = Environment.GetFolderPath(Environment.SpecialFolder.Personal);                // Documents folder
                var newFilePath     = Path.Combine(documentsPath, "CouponBanana2.pkpass");
                var builtInPassPath = Path.Combine(System.Environment.CurrentDirectory, "CouponBanana2.pkpass");
                if (!System.IO.File.Exists(newFilePath))
                {
                    System.IO.File.Copy(builtInPassPath, newFilePath);
                }

                NSData nsdata;
                using (FileStream oStream = File.Open(newFilePath, FileMode.Open)) {
                    nsdata = NSData.FromStream(oStream);
                }

                var err     = new NSError(new NSString("42"), -42);
                var newPass = new PKPass(nsdata, out err);

                bool alreadyExists = library.Contains(newPass);

                if (alreadyExists)
                {
                    new UIAlertView(newPass.LocalizedDescription + " Tapped"
                                    , "Already exists", null, "OK", null).Show();
                }
                else
                {
//					new UIAlertView(newPass.LocalizedDescription + " Tapped"
//					                , "Isn't in Pass Library", null, "OK, add it", null).Show();

                    var pkapvc = new PKAddPassesViewController(newPass);
                    NavigationController.PresentModalViewController(pkapvc, true);
                }
            }
        }
Ejemplo n.º 9
0
 public TableSource(PKPass[] items, PKPassLibrary library)
 {
     tableItems = items;
     this.library = library;
 }
 void RenderPass(PKPass[] passes)
 {
     if (passes.Length == 0) {
         // NO PASS
         showPass.Alpha = 0f;
         passHeading.Text = "No Event Ticket\nin Passbook";
         passImage.Image = UIImage.FromBundle("Images/NoTicketSlash");
     } else {
         currentPass = passes[0];
         showPass.Alpha = 1f;
         passHeading.Text = "MonkeySpace Ticket Available";
         passImage.Image = UIImage.FromBundle("Images/Monkey");
     }
 }
Ejemplo n.º 11
0
		/// <summary>
		/// PKLibrary.Replace() doesn't require user to agreee (no UI)
		/// BUT only works if the pass already exists
		/// </summary>
		void HandleReplaceTouchUpInside (object sender, EventArgs e)
		{
			if (PKPassLibrary.IsAvailable) {

				var documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal); // Documents folder
				var newFilePath = Path.Combine (documentsPath, "CouponBanana2.pkpass");
				var builtInPassPath = Path.Combine (System.Environment.CurrentDirectory, "CouponBanana2.pkpass");
				if (!System.IO.File.Exists(newFilePath))
					System.IO.File.Copy (builtInPassPath, newFilePath);

				NSData nsdata;
				using ( FileStream oStream = File.Open (newFilePath, FileMode.Open ) ) {
					nsdata = NSData.FromStream ( oStream );
				}

				var err = new NSError(new NSString("42"), -42);
				var newPass = new PKPass(nsdata,out err);

				bool alreadyExists = library.Contains (newPass);

				if (alreadyExists) {
					library.Replace (newPass);
					new UIAlertView(newPass.LocalizedDescription + " replaced!"
					                , "your choice if you offer UI when you update", null, "OK", null).Show();
				} else
					new UIAlertView(newPass.LocalizedDescription + " doesn't exit"
					                , "Can't *replace* if the pass isn't already in library", null, "OK", null).Show();
			}
		}
Ejemplo n.º 12
0
		void HandleAddTouchUpInside (object sender, EventArgs e)
		{
			if (PKPassLibrary.IsAvailable) {

				var documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal); // Documents folder
				var newFilePath = Path.Combine (documentsPath, "CouponBanana2.pkpass");
				var builtInPassPath = Path.Combine (System.Environment.CurrentDirectory, "CouponBanana2.pkpass");
				if (!System.IO.File.Exists(newFilePath))
					System.IO.File.Copy (builtInPassPath, newFilePath);

				NSData nsdata;
				using ( FileStream oStream = File.Open (newFilePath, FileMode.Open ) ) {
					nsdata = NSData.FromStream ( oStream );
				}

				var err = new NSError(new NSString("42"), -42);
				var newPass = new PKPass(nsdata,out err);

				bool alreadyExists = library.Contains (newPass);

				if (alreadyExists) {
					new UIAlertView(newPass.LocalizedDescription + " Tapped"
					                , "Already exists", null, "OK", null).Show();
				} else {
//					new UIAlertView(newPass.LocalizedDescription + " Tapped"
//					                , "Isn't in Pass Library", null, "OK, add it", null).Show();

					var pkapvc = new PKAddPassesViewController(newPass);
					NavigationController.PresentModalViewController (pkapvc, true);
				}
			}
		}