Ejemplo n.º 1
0
        public static IOSNativeBranch.BranchUniversalObject ToNativeUniversalObject(BranchUniversalObject obj)
        {
            var res = new IOSNativeBranch.BranchUniversalObject();

            if (obj != null)
            {
                if (obj.metadata != null)
                {
                    foreach (String key in obj.metadata.Keys)
                    {
                        res.AddMetadataKey(key, obj.metadata [key]);
                    }
                }

                res.Keywords            = ToNSObjectArray(obj.keywords);
                res.CanonicalIdentifier = obj.canonicalIdentifier != null ? obj.canonicalIdentifier : "";
                res.Title = obj.title != null ? obj.title : "";
                res.ContentDescription = obj.contentDescription != null ? obj.contentDescription : "";
                res.ImageUrl           = obj.imageUrl != null ? obj.imageUrl : "";
                res.Type             = obj.type != null ? obj.type : "";
                res.ContentIndexMode = (IOSNativeBranch.ContentIndexMode)obj.contentIndexMode;

                if (obj.expirationDate.HasValue)
                {
                    res.ExpirationDate = (NSDate)obj.expirationDate.Value;
                }
            }

            return(res);
        }
Ejemplo n.º 2
0
        public override void ShareLink(IBranchLinkShareInterface callback,
                                       BranchUniversalObject universalObject,
                                       BranchLinkProperties linkProperties,
                                       string message)
        {
            IOSNativeBranch.BranchUniversalObject buo = BranchIOSUtils.ToNativeUniversalObject(universalObject);
            IOSNativeBranch.BranchLinkProperties  blp = BranchIOSUtils.ToNativeLinkProperties(linkProperties);
            UIKit.UIWindow window = UIKit.UIApplication.SharedApplication.KeyWindow;

            buo.ShowShareSheetWithLinkProperties(blp, message, window.RootViewController, delegate(string url, bool isShared) {});
        }
Ejemplo n.º 3
0
        public override void GetShortURL(IBranchUrlInterface callback,
                                         BranchUniversalObject universalObject,
                                         BranchLinkProperties linkProperties)
        {
            BranchUrlListener obj = new BranchUrlListener(callback);

            callbacksList.Add(obj as Object);

            IOSNativeBranch.BranchUniversalObject buo = BranchIOSUtils.ToNativeUniversalObject(universalObject);
            IOSNativeBranch.BranchLinkProperties  blp = BranchIOSUtils.ToNativeLinkProperties(linkProperties);

            buo.GetShortUrlWithLinkProperties(blp, obj.GetShortUrlCallback);
        }
        public static Dictionary <string, object> ToDictionary(IOSNativeBranch.BranchUniversalObject universalObject)
        {
            if (universalObject == null)
            {
                return(new Dictionary <string, object> ());
            }

            NSString[] keys = new NSString[] {
                (NSString)"$canonical_identifier",
                (NSString)"$canonical_url",
                (NSString)"$og_title",
                (NSString)"$og_description",
                (NSString)"$og_image_url",
                (NSString)"$content_type",
                (NSString)"$publicly_indexable",
                (NSString)"$keywords",
                (NSString)"$exp_date",
                (NSString)"metadata"
            };

            NSObject[] values = new NSObject[] {
                NSObject.FromObject(universalObject.CanonicalIdentifier != null ? universalObject.CanonicalIdentifier : "" as object),
                NSObject.FromObject(universalObject.CanonicalUrl != null ? universalObject.CanonicalUrl : "" as object),
                NSObject.FromObject(universalObject.Title != null ? universalObject.Title : "" as object),
                NSObject.FromObject(universalObject.ContentDescription != null ? universalObject.ContentDescription : "" as object),
                NSObject.FromObject(universalObject.ImageUrl != null ? universalObject.ImageUrl : "" as object),
                NSObject.FromObject(universalObject.Type != null ? universalObject.Type: "" as object),
                NSObject.FromObject(((int)universalObject.ContentIndexMode).ToString() as object),
                NSObject.FromObject(universalObject.Keywords != null ? universalObject.Keywords : "" as object),
                NSObject.FromObject(universalObject.ExpirationDate != null ? ((DateTime)universalObject.ExpirationDate).Millisecond.ToString() : "" as object),
                NSObject.FromObject(universalObject.Metadata != null ? universalObject.Metadata : "" as object)
            };

            NSDictionary dict = NSDictionary.FromObjectsAndKeys(values, keys);

//			NSDictionary dict = new NSDictionary (
//				"$canonical_identifier", universalObject.CanonicalIdentifier ? universalObject.CanonicalIdentifier : "",
//				"$canonical_url", universalObject.CanonicalUrl ? universalObject.CanonicalUrl : "",
//				"$og_title", universalObject.Title ? universalObject.Title : "",
//				"$og_description", universalObject.ContentDescription ? universalObject.ContentDescription : "",
//				"$og_image_url", universalObject.ImageUrl ? universalObject.ImageUrl : "",
//				"$content_type", universalObject.Type ? universalObject.Type: "",
//				"$publicly_indexable", universalObject.ContentIndexMode.ToString(),
//				"$keywords", universalObject.Keywords ? universalObject.Keywords : "",
//				"$exp_date", universalObject.ExpirationDate ? ((DateTime)universalObject.ExpirationDate).Millisecond.ToString () : "",
//				"metadata", universalObject.Metadata ? universalObject.Metadata : ""
//			);

            return(ToDictionary(dict));
        }
Ejemplo n.º 5
0
        public static Dictionary <string, object> ToDictionary(IOSNativeBranch.BranchUniversalObject universalObject)
        {
            if (universalObject == null)
            {
                return(new Dictionary <string, object> ());
            }

            var keywordsList = new List <object>();

            if (universalObject.Keywords != null)
            {
                foreach (string obj in universalObject.Keywords)
                {
                    keywordsList.Add(obj);
                }
            }

            NSError error    = null;
            NSData  jsonData = NSJsonSerialization.Serialize(universalObject.ContentMetadata.Dictionary(), 0, out error);

            string jsonStr = jsonData.ToString();
            Dictionary <string, object> metadataDict = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonStr);

            var dict = new Dictionary <string, object>();

            dict.Add("$canonical_identifier", universalObject.CanonicalIdentifier != null ? universalObject.CanonicalIdentifier : "");
            dict.Add("$canonical_url", universalObject.CanonicalUrl != null ? universalObject.CanonicalUrl : "");
            dict.Add("$og_title", universalObject.Title != null ? universalObject.Title : "");
            dict.Add("$og_description", universalObject.ContentDescription != null ? universalObject.ContentDescription : "");
            dict.Add("$og_image_url", universalObject.ImageUrl != null ? universalObject.ImageUrl : "");
            dict.Add("$publicly_indexable", universalObject.PubliclyIndex ? "0" : "1");
            dict.Add("$locally_indexable", universalObject.LocallyIndex ? "0" : "1");
            dict.Add("$exp_date", universalObject.ExpirationDate != null ? (universalObject.ExpirationDate.SecondsSinceReferenceDate * 1000).ToString() : "");

            if (keywordsList != null)
            {
                dict.Add("$keywords", keywordsList);
            }

            if (metadataDict != null)
            {
                dict.Add("metadata", metadataDict);
            }

            return(dict);
        }
Ejemplo n.º 6
0
        public void InitCallback(IOSNativeBranch.BranchUniversalObject buo,
                                 IOSNativeBranch.BranchLinkProperties blp,
                                 NSError error)
        {
            if (callback == null)
            {
                return;
            }

            if (error == null)
            {
                callback.InitSessionComplete(new BranchUniversalObject(BranchIOSUtils.ToDictionary(buo)),
                                             new BranchLinkProperties(BranchIOSUtils.ToDictionary(blp)));
            }
            else
            {
                BranchError err = new BranchError(error.Description, (int)error.Code);
                callback.SessionRequestError(err);
            }
        }
        public static Dictionary <string, object> ToDictionary(IOSNativeBranch.BranchUniversalObject universalObject)
        {
            if (universalObject == null)
            {
                return(new Dictionary <string, object> ());
            }

            NSString[] keys = new NSString[] {
                (NSString)"$canonical_identifier",
                (NSString)"$canonical_url",
                (NSString)"$og_title",
                (NSString)"$og_description",
                (NSString)"$og_image_url",
                (NSString)"$publicly_indexable",
                (NSString)"$locally_indexable",
                (NSString)"$keywords",
                (NSString)"$exp_date",
                (NSString)"metadata"
            };

            NSObject[] values = new NSObject[] {
                NSObject.FromObject(universalObject.CanonicalIdentifier != null ? universalObject.CanonicalIdentifier : "" as object),
                NSObject.FromObject(universalObject.CanonicalUrl != null ? universalObject.CanonicalUrl : "" as object),
                NSObject.FromObject(universalObject.Title != null ? universalObject.Title : "" as object),
                NSObject.FromObject(universalObject.ContentDescription != null ? universalObject.ContentDescription : "" as object),
                NSObject.FromObject(universalObject.ImageUrl != null ? universalObject.ImageUrl : "" as object),
                NSObject.FromObject((universalObject.PubliclyIndex ? "0" : "1") as object),
                NSObject.FromObject((universalObject.LocallyIndex ? "0" : "1") as object),
                NSObject.FromObject(universalObject.Keywords != null ? NSArray.FromStrings(universalObject.Keywords) : "" as object),
                NSObject.FromObject(universalObject.ExpirationDate != null ? (universalObject.ExpirationDate.SecondsSinceReferenceDate * 1000).ToString() : "" as object),
                NSObject.FromObject(universalObject.ContentMetadata != null ? universalObject.ContentMetadata.Dictionary() : "" as object)
            };

            NSDictionary dict = NSDictionary.FromObjectsAndKeys(values, keys);

            return(ToDictionary(dict));
        }
Ejemplo n.º 8
0
        public static IOSNativeBranch.BranchUniversalObject ToNativeUniversalObject(BranchUniversalObject obj)
        {
            var res = new IOSNativeBranch.BranchUniversalObject();

            if (obj != null)
            {
                res.Keywords            = obj.keywords.ToArray();
                res.CanonicalIdentifier = obj.canonicalIdentifier != null ? obj.canonicalIdentifier : "";
                res.CanonicalUrl        = obj.canonicalUrl != null ? obj.canonicalUrl : "";
                res.Title = obj.title != null ? obj.title : "";
                res.ContentDescription = obj.contentDescription != null ? obj.contentDescription : "";
                res.ImageUrl           = obj.imageUrl != null ? obj.imageUrl : "";
                res.PubliclyIndex      = obj.contentIndexMode == 0;
                res.LocallyIndex       = obj.localIndexMode == 0;

                if (obj.expirationDate.HasValue)
                {
                    DateTime reference = TimeZoneInfo.ConvertTimeFromUtc(new DateTime(2001, 1, 1, 0, 0, 0), TimeZoneInfo.Local);
                    res.ExpirationDate = NSDate.FromTimeIntervalSinceReferenceDate((obj.expirationDate.Value - reference).TotalSeconds);
                }

                if (obj.metadata != null)
                {
                    foreach (string key in obj.metadata.Metadata.Keys)
                    {
                        if (key.Equals("$content_schema"))
                        {
                            res.ContentMetadata.ContentSchema = obj.metadata.Metadata["$content_schema"].ToString();
                        }
                        if (key.Equals("$quantity"))
                        {
                            res.ContentMetadata.Quantity = Convert.ToDouble(obj.metadata.Metadata["$quantity"].ToString());
                        }
                        if (key.Equals("$price"))
                        {
                            res.ContentMetadata.Price = new NSDecimalNumber(obj.metadata.Metadata["$price"].ToString());
                        }
                        if (key.Equals("$currency"))
                        {
                            res.ContentMetadata.Currency = obj.metadata.Metadata["$currency"].ToString();
                        }
                        if (key.Equals("$sku"))
                        {
                            res.ContentMetadata.Sku = obj.metadata.Metadata["$sku"].ToString();
                        }
                        if (key.Equals("$product_name"))
                        {
                            res.ContentMetadata.ProductName = obj.metadata.Metadata["$product_name"].ToString();
                        }
                        if (key.Equals("$product_brand"))
                        {
                            res.ContentMetadata.ProductBrand = obj.metadata.Metadata["$product_brand"].ToString();
                        }
                        if (key.Equals("$product_category"))
                        {
                            res.ContentMetadata.ProductCategory = obj.metadata.Metadata["$product_category"].ToString();
                        }
                        if (key.Equals("$condition"))
                        {
                            res.ContentMetadata.Condition = obj.metadata.Metadata["$condition"].ToString();
                        }
                        if (key.Equals("$product_variant"))
                        {
                            res.ContentMetadata.ProductVariant = obj.metadata.Metadata["$product_variant"].ToString();
                        }
                        if (key.Equals("$rating_average"))
                        {
                            res.ContentMetadata.RatingAverage = Convert.ToDouble(obj.metadata.Metadata["$rating_average"].ToString());
                        }
                        if (key.Equals("$rating_count"))
                        {
                            res.ContentMetadata.RatingCount = new nint(Convert.ToInt32(obj.metadata.Metadata["$rating_count"].ToString()));
                        }
                        if (key.Equals("$rating_max"))
                        {
                            res.ContentMetadata.RatingMax = Convert.ToDouble(obj.metadata.Metadata["$rating_max"].ToString());
                        }
                        if (key.Equals("$address_street"))
                        {
                            res.ContentMetadata.AddressStreet = obj.metadata.Metadata["$address_street"].ToString();
                        }
                        if (key.Equals("$address_city"))
                        {
                            res.ContentMetadata.AddressCity = obj.metadata.Metadata["$address_city"].ToString();
                        }
                        if (key.Equals("$address_region"))
                        {
                            res.ContentMetadata.AddressRegion = obj.metadata.Metadata["$address_region"].ToString();
                        }
                        if (key.Equals("$address_country"))
                        {
                            res.ContentMetadata.AddressCountry = obj.metadata.Metadata["$address_country"].ToString();
                        }
                        if (key.Equals("$address_postal_code"))
                        {
                            res.ContentMetadata.AddressPostalCode = obj.metadata.Metadata["$address_postal_code"].ToString();
                        }
                        if (key.Equals("$latitude"))
                        {
                            res.ContentMetadata.Latitude = Convert.ToDouble(obj.metadata.Metadata["$latitude"].ToString());
                        }
                        if (key.Equals("$longitude"))
                        {
                            res.ContentMetadata.Longitude = Convert.ToDouble(obj.metadata.Metadata["$longitude"].ToString());
                        }
                    }

                    foreach (string val in obj.metadata.GetImageCaptions())
                    {
                        res.ContentMetadata.ImageCaptions.Add((NSString)val);
                    }

                    foreach (string key in obj.metadata.GetCustomMetadata().Keys)
                    {
                        res.ContentMetadata.CustomMetadata.Add((NSString)key, (NSString)obj.metadata.GetCustomMetadata()[key]);
                    }
                }
            }

            return(res);
        }