internal static void UpdateInfoPlistWithSkAdNetworkIds(string pathToPlistFile)
        {
            var provider = new SkAdNetworkLocalSourceProvider();
            var ids      = new HashSet <string>();

            try {
                SkAdNetworkParser.GetAllParsers().ToList().ForEach(parser => {
                    provider.GetSources(k_SkAdNetworksFileName, parser.GetExtension()).ToList().ForEach(source => {
                        ids.UnionWith(parser.ParseSource(source));
                    });
                });
            }
            catch (Exception e) {
                Debug.LogError($"Failed to parse SKAdNetwork files due to following reason: {e.Message}");
            }

            if (!ids.Contains(k_UnitySkAdNetworkId))
            {
                ids.Add(k_UnitySkAdNetworkId);
            }

            try {
                WriteSkAdNetworkIdsToInfoPlist(ids, pathToPlistFile);
            }
            catch (Exception e) {
                Debug.LogError($"Failed to update info.plist file due to following reason: {e.Message}");
            }
        }
Example #2
0
        public HashSet <string> ParseSource(ISkAdNetworkSource source)
        {
            var foundIds = new HashSet <string>();

            try {
                string[] lines;
                using (var reader = new StreamReader(source.Open())) {
                    lines = reader.ReadToEnd().Split(Environment.NewLine.ToCharArray());
                }

                lines.Where(url => !string.IsNullOrEmpty(url))
                .Where(url => Uri.IsWellFormedUriString(url, UriKind.Absolute))
                .ToList().ForEach(url => {
                    ISkAdNetworkParser parser = null;
                    switch (GetExtensionFromPath(url))
                    {
                    case SkAdNetworkFileExtension.XML:
                        parser = SkAdNetworkParser.GetParser(SkAdNetworkFileExtension.XML);
                        break;

                    case SkAdNetworkFileExtension.JSON:
                        parser = SkAdNetworkParser.GetParser(SkAdNetworkFileExtension.JSON);
                        break;
                    }

                    if (parser == null)
                    {
                        Debug.LogWarning($"[Unity SKAdNetwork Parser] Unsupported file extension, No parser available to parse SKAdNetwork file: {source.Path} ");
                        return;
                    }

                    foundIds.UnionWith(parser.ParseSource(new SkAdNetworkRemoteSource(url)));
                });
            }
            catch (Exception) {
                Debug.LogWarning($"[Unity SKAdNetwork Parser] Unable to parse SKAdNetwork file: {source.Path}");
            }

            return(foundIds);
        }