Xamarin: Visual Studio Start iOS app always terminates (found work-around) - xamarin

Xamarin Noob
Xamarin.Forms Noob
I am all hooked up. Business license on iOS and Android and developing from VS 2013.
I created the initial sample from the Xamarin Intro to Forms.
I 'Start'ed the app and it ran fine on my Mac. I saw the 'Hello, Forms !' label in the running app in the iOS simulator on my Mac Build Machine.
I then replaced the following code in my App.cs
public static Page GetMainPage()
{
return new ContentPage
{
Content = new Label
{
Text = "Hello, Forms !",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
},
};
}
with:
public static Page GetMainPage()
{
return new ContentPage()
{
Content = new StackLayout
{
Spacing = 10,
Children =
{
new Label
{
Text = "Stop",
BackgroundColor = Color.Red,
Font = Font.SystemFontOfSize(20)
},
new Label
{
Text = "Slow down",
BackgroundColor = Color.Yellow,
Font = Font.SystemFontOfSize(20)
},
new Label
{
Text = "Go",
BackgroundColor = Color.Green,
Font = Font.SystemFontOfSize(20)
}
}
}
};
}
That's all I did, but now the app will not run in the simulator - it always exists as soon as it starts...
I put the original code back again, and it still doesn't start.
I always see (in My VS 12013 Mac Server Log)
[10-Nov-2014 15:43:32] Request handled in 4.129ms
[10-Nov-2014 15:43:37] Request handled in 3.728ms
[10-Nov-2014 15:43:40] stdout: Starting iPhone 5s
Launching application
Application launched. PID = 2872
Press enter to terminate the application
>
Application Terminated
[10-Nov-2014 15:43:42] Request handled in 3.898ms
[10-Nov-2014 15:43:48] Request handled in 4.031ms
etc....
I have exited both the iOS simulator and VS 2013, paired them again, all to no avail...
What could possibly be wrong?
EDIT
Infact, when the app becomes visible in the simulators view of icons, clicking it brings up the original version of "Hello, Forms!" - so my new code is never deployed to the simulator...
EDIT 2
Ok, I got the new content moving and got it running:
I had to manually "Reset content on device" in the iOS simulator on the Mac.
I also had to manually clean each project in VS 2013 - just rebuilding the solution doesn't do anything to the content being sent to the Mac iOS simulator server, I guess.
I hope this helps someone as new as I am.

Try removing "." from your app's name in Info.plist file.

After fiddling..
The way to fix this is to change the build config on the solution.
In a fresh Xamarin.Forms solution in Visual Studio, you might have:
Solution 'MyXFormsSample' (3 projects)
v MyXFormsSample (Portable)
> Properties
> References
> App.cs
packages.config
> MyXFormsSample.Android
> MyXFormsSample.iOS
It seems that by default, in the solution's Configuration Manager's build configuration, the portable code project is not set to build for the iPhoneSimulator platform
I clicked that on for the debug, and also release, solution configurations, and still I had to Reset Content on the Mac's iOS simulator before debugging, then all I had to do was press the green 'Start' button in the menu - all was updated and released to the Mac Build server's iOS Simulator.

Related

Xcode 13 will not show Preview

I have a brand new 21 Macbook Pro with the M1 Pro chip. I installed Xcode from the app store, and I have also installed Xcode beta. I am completely up to date on Monterey as well.
I am building a swift UI app and I cannot get preview to work at all.
I get the following error.
== PREVIEW UPDATE ERROR:
MessageSendFailure: Message send failure for send previewInstances message to agent
==================================
| RemoteHumanReadableError
|
| LoadingError: failed to load library at path "/Users/user/Library/Developer/Xcode/DerivedData/Test-gfnknimtrrhvztavjffxvzjvrvmo/Build/Intermediates.noindex/Previews/Test/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/arm64/SwiftUIView.2.preview-thunk.dylib": Optional(dlopen(/Users/user/Library/Developer/Xcode/DerivedData/Test-gfnknimtrrhvztavjffxvzjvrvmo/Build/Intermediates.noindex/Previews/Test/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/arm64/SwiftUIView.2.preview-thunk.dylib, 0x0002): tried: '/Users/brandon/Library/Developer/Xcode/DerivedData/Test-gfnknimtrrhvztavjffxvzjvrvmo/Build/Intermediates.noindex/Previews/Test/Products/Debug-iphonesimulator/SwiftUIView.2.preview-thunk.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Users/user/Library/Developer/Xcode/DerivedData/Test-gfnknimtrrhvztavjffxvzjvrvmo/Build/Intermediates.noindex/Previews/Test/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/arm64/SwiftUIView.2.preview-thunk.dylib' (no such file), '/Users/user/Library/Developer/Xcode/DerivedData/Test-gfnknimtrrhvztavjffxvzjvrvmo/Build/Intermediates.noindex/Previews/Test/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/arm64/SwiftUIView.2.preview-thunk.dylib' (no such file), '/usr/lib/SwiftUIView.2.preview-thunk.dylib' (no such file))
I have tried to reinstall xcode, reboot you name it.
I can get simulator to work...
Any ideas?
Nothing I tried worked, including running:
sudo xcodebuild -license in the terminal
Deleting derived data
Sign in again to GitHub
Restarts
Only when I toggled Automatically refresh canvas (Editor > Canvas) I got preview back.
Preview was failing on a new default projects as well.
I had the same problem and found a solution here:
https://developer.apple.com/forums/thread/691237
I was not signed in to GitHub so as suspected, it does not play a role.
It seems Xcode got in to an invalid state. I suspect that simply disabling and enabling automatic signing would resolve the issue but I also cleared the Container folder for my project as suggested in the post.
Same issue and resolved it by change Mac's user name to lowercase.
Username->username
I had the same problem because I downloaded a GitHub project (an existing SwiftUI project) and I didn't create a new SwiftUI project from scratch. I notice the SwiftUI view doesn't had the PreviewProvider struct at the bottom:
struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
SwiftUIView()
}
}
After adding the PreviewProvider struct, Xcode showed the Preview.

How do I create a WKWebView App for MacOS

I have an HTML5 App developed in XCode in the IOS App Store and I wish to create a copy of that app for the Mac App Store.
I thought this would be easy but I cannot find any easy tutorials to follow, certainly not using XCode 11 and Swift 5.1. I do not want to go down the automated route provided in Mac OS 10.15
When I built the default Hello World App that comes with XCode 11, it will not run on 10.14! I do not want to upgrade to 10.15 yet, primarily because I want the app to work on earlier versions of MacOS
Anyone who can provide me with a reference to a working example of a WKWebView App loading local files that runs in XCode 11 on Max OS 10.14 will be my hero.
Step 1 - Install XCode 11 and open it.
Step 2 - Select "File" and "New" and "Project" from the main menu.
Step 3 - Select "App" (top left) and Select "Next" (bottom right).
Step 4 - Give your app a name, for User Interface select "Storyboard" and then select "Next".
Step 5 - Select a folder for where to store your new app on your computer and select "Create".
Step 6 - In XCode Navigator (left hand pane) select "Add Files" from the context menu.
Step 7 - Select the folder containing your html/javascript/css/image files - in this example I assume the folder will have the name "www" but it can be anything - just remember to change "www" in the code shown below to what you want.
Step 8 - Select "Create folder references for any added folders" and select "Add"
Step 9 - Select "ViewController.swift" from the Navigator pane and replace everything with with code shown below, changing "www" to the folder name containing your html etc and changing "AppName" to the name of your html file.
Step 10 - Press "Run" and use your new app.
For how to publish it and add other functionality (such as in app purchases) refer to Apple Developer and other internet resources/stack overflow questions.
import Cocoa
import WebKit
class ViewController: NSViewController, WKUIDelegate
{
var webView: WKWebView!
override func loadView()
{
let webConfiguration = WKWebViewConfiguration ();
webConfiguration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs");
webView = WKWebView (frame: CGRect(x:0, y:0, width:800, height:600), configuration:webConfiguration);
webView.uiDelegate = self ;
view = webView;
}
override func viewDidLoad() {
super.viewDidLoad()
if let url = Bundle.main.url ( forResource: "AppName"
, withExtension: "html"
, subdirectory: "www")
{
let path = url.deletingLastPathComponent();
self.webView.loadFileURL ( url
, allowingReadAccessTo: path);
self.view = webView ;
}
}
}
Using Xcode 12 and Big Sur I had to go to the project properties, select the Signing & Capabilities tab, and check Outgoing Connections (Client) under the App Sandbox to get the excellent answer from Steve Brooker to work.

xamarin UITest does not start "clean" on iOS

I'm writing UI tests in Xamarin UITest and when I run several tests behind the app never really is in a "clean" state. So when test A is executed and it is on screen y, test B will start and the app will be on screen y. Also some configurations are also present.
I tried to set the AppDataMode to clear in the AppInitializer.cs but this has no effect at all. On Android this problem does not occure. Tips and suggestions are more then welcome!
Thanks in advance
Apparently this is a known issue and the solution will be to force the ios simulator
public class AppInitializer
{
public static IApp StartApp(Platform platform)
{
if (platform == Platform.Android)
{
return ConfigureApp.Android.StartApp();
}
Environment.SetEnvironmentVariable("UITEST_FORCE_IOS_SIM_RESTART", "1"); // <---- Add this line
return ConfigureApp.iOS.StartApp();
}
}
According to JGoldbverger from Xamarin. Source => https://forums.xamarin.com/discussion/149966/xamarin-uitest-does-not-clean-my-app-on-ios/.

xamarin application not quitting right

I noticed something strange with my Xamarin application.
First in Xamarin: Running the Application was fine until I click the upper right X to close the App. In Xamarin the button on the left is still a red square and I can "stop the current startup project".
Second: after packing up the application (7zip) and starting it out of the archive, after closing the app, 7zip told me to stop the application before it is able to close the archive.
Is there anything i'm missing here? Do i have to setup anything to shutdown the App properly?
there even is a OnDeleteEvent
protected void OnDeleteEvent(object sender, DeleteEventArgs a)
{
Application.Quit();
a.RetVal = true;
}
but with a breakpoint there, it seems not to be used when clicking the X-Button.
Note: I'm using the GTK#2.0 Project template with Xamarin 6.2
i had to add the line
this.DeleteEvent += new global::Gtk.DeleteEventHandler(this.OnDeleteEvent);
into the sourcecode of my MainWindow. Somehow this line was missing.
It's working as intended now.

Folder display mode olFolderDisplayNoNavigation causing artifacts in Outlook 2013

A Outlook Add-in explorer window with the folder display mode setting olFolderDisplayNoNavigation is causing errors within the GUI of Outlook 2013. In Outlook 2010 the setting worked fine, but now it shows artifacts / UI glitches on the left menu pane, which should not be displayed at all. Is there any way to fix this behavior?
public void open_myExplorer(IRibbonControl control)
{
Recipient myRecipient = Globals.ThisAddIn.Application.Session.CreateRecipient("user#email.com");
MAPIFolder mFolder = Globals.ThisAddIn.Application.Session.GetSharedDefaultFolder(myRecipient, OlDefaultFolders.olFolderNotes);
Explorer myExplorer = Globals.ThisAddIn.Application.Explorers.Add(mFolder, OlFolderDisplayMode.olFolderDisplayNoNavigation);
myExplorer.Display();
}
I've solved the problem by using
myExplorer.NavigationPane.IsCollapsed = true;
myExplorer.ShowPane(OlPane.olNavigationPane, false);
instead of setting the display mode to olFolderDisplayNoNavigation.

Resources