Пример #1
0
        static string RenderIosTab(iOSConfig ios)
        {
            var sb = new StringBuilder();

            sb.AppendLine("## Minimum Version: " + ios.MinVersion);

            RenderAppDelegate(ios, sb);
            RenderInfoPlist(ios, sb);
            RenderEntitlementsPlist(ios, sb);
            return(sb.ToString());
        }
Пример #2
0
        static void RenderAppDelegate(iOSConfig ios, StringBuilder sb)
        {
            if (!ios.UsesPush && !ios.UsesJobs && !ios.UsesBgTransfers)
            {
                return;
            }

            sb
            .AppendLine("### AppDelegate")
            .AppendLine()
            .AppendLine("```csharp")
            .AppendLine("using System;")
            .AppendLine("using Foundation;")
            .AppendLine("using Xamarin.Forms.Platform.iOS;")
            .AppendLine("using Shiny;")
            .AppendLine()
            .AppendLine("namespace YourIosApp")
            .AppendLine("{")
            .AppendLine("   [Register(\"AppDelegate\")]")
            .AppendLine("   public partial class AppDelegate : FormsApplicationDelegate")
            .AppendLine("   {")
            .AppendLine("       public override bool FinishedLaunching(UIApplication app, NSDictionary options)")
            .AppendLine("       {")
            .AppendLine("           this.ShinyFinishedLaunching(new Samples.SampleStartup());")
            .AppendLine("           global::Xamarin.Forms.Forms.Init();")
            .AppendLine("           this.LoadApplication(new Samples.App());")
            .AppendLine("       }");

            if (ios.UsesJobs)
            {
                sb.AppendLine("public override void PerformFetch(UIApplication application, Action<UIBackgroundFetchResult> completionHandler) => this.ShinyPerformFetch(completionHandler);");
            }

            if (ios.UsesPush)
            {
                sb
                .AppendLine("public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) => this.ShinyRegisteredForRemoteNotifications(deviceToken);")
                .AppendLine("public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error) => this.ShinyFailedToRegisterForRemoteNotifications(error);")
                .AppendLine("public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler) => this.ShinyDidReceiveRemoteNotification(userInfo, completionHandler);");
            }

            if (ios.UsesBgTransfers)
            {
                sb.AppendLine("public override void HandleEventsForBackgroundUrl(UIApplication application, string sessionIdentifier, Action completionHandler) => this.ShinyHandleEventsForBackgroundUrl(sessionIdentifier, completionHandler);");
            }

            sb
            .AppendLine("\t}")
            .AppendLine("}")
            .AppendLine("```");
        }
Пример #3
0
        static void RenderEntitlementsPlist(iOSConfig ios, StringBuilder sb)
        {
            if (ios.EntitlementPlistValues == null && !ios.UsesPush)
            {
                return;
            }

            sb
            .AppendXmlCode("Entitlements.plist")
            .AppendLine("<!DOCTYPE plist PUBLIC \" -//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">")
            .AppendLine("<plist version=\"1.0\">")
            .AppendLine("<dict>");

            if (ios.EntitlementPlistValues != null)
            {
                foreach (var pair in ios.EntitlementPlistValues)
                {
                    sb.AppendLine($"    <key>{pair.Key}</key>");
                    if (pair.Value.StartsWith("<"))
                    {
                        sb.AppendLine($"    {pair.Value}");
                    }
                    else
                    {
                        sb.AppendLine($"    <string>{pair.Value}</string>");
                    }
                }
            }

            if (ios.UsesPush)
            {
                sb
                .AppendLine("   <key>aps-environment</key>")
                .AppendLine("   <string>development OR production</string>");
            }
            sb
            .AppendLine("</dict>")
            .AppendLine("</plist>")
            .AppendLine("```");
        }
Пример #4
0
        static void RenderInfoPlist(iOSConfig ios, StringBuilder sb)
        {
            if (!ios.UsesBgTransfers && !ios.UsesJobs && !ios.UsesPush && ios.InfoPlistValues == null && ios.BackgroundModes == null)
            {
                return;
            }

            sb
            .AppendXmlCode("Info.plist")
            .AppendLine("<!DOCTYPE plist PUBLIC \" -//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">")
            .AppendLine("<plist version=\"1.0\">")
            .AppendLine("<dict>");

            if (ios.UsesJobs)
            {
                sb.Append(@"
    <key>BGTaskSchedulerPermittedIdentifiers</key>
    <array>
        <string>com.shiny.job</string>
        <string>com.shiny.jobpower</string>
        <string>com.shiny.jobnet</string>
        <string>com.shiny.jobpowernet</string>
    </array>
");
            }

            if (ios.InfoPlistValues != null)
            {
                foreach (var value in ios.InfoPlistValues)
                {
                    sb
                    .AppendLine($"    <key>{value}</key>")
                    .AppendLine("    <string>Say something useful here that your users will understand</string>");
                }
            }

            if (ios.BackgroundModes != null || ios.UsesJobs || ios.UsesPush)
            {
                sb
                .AppendLine("    <key>UIBackgroundModes</key>")
                .AppendLine("    <array>");

                if (ios.UsesJobs)
                {
                    sb
                    .AppendLine("       <string>processing</string>")
                    .AppendLine("       <string>fetch</string>");
                }
                if (ios.UsesPush)
                {
                    sb.AppendLine("     <string>remote-notification</string>");
                }
                if (ios.BackgroundModes != null)
                {
                    foreach (var bg in ios.BackgroundModes)
                    {
                        sb.AppendLine($"        <string>{bg}</string>");
                    }
                }
                sb.AppendLine("    </array>");
            }
            sb
            .AppendLine("</dict>")
            .AppendLine("</plist>")
            .AppendLine("```");
        }