I use Code Contracts in my code, my app runs fine on the emulator. When I deploy it on a device, it fails/crashes whenever Contract statement is executed.
public static HTTPRequest CreateGetRequest(string url,
bool shouldUseCustomTimeout)
{
// preconditions
Contract.Requires<ArgumentException>(!string.IsNullOrWhiteSpace(url));
return new HTTPRequest(url,
System.Net.Http.HttpMethod.Get,
shouldUseCustomTimeout);
}
Is the code contract supported on actual device? Should I install a separate extension?
Is the code contract supported on actual device?
Yes.
I got it working by following the steps on this blog: http://blog.stephencleary.com/2011/01/simple-and-easy-code-contracts.html
It turns out that I had to enable for the library projects too. I was setting code contracts only for the test app.
Related
Is there a way to run code in the app from a UI test in Xcode 7? This is possible with application tests (since the tests run in the app), but there doesn't appear to be a simple way with UI tests.
Has anyone figured out a workaround?
The most straight forward way to run code in the app you are executing your app from UI tests is to supply launchArguments via XCUIApplication.
ui test code
import XCTest
class UITestUITests: XCTestCase {
override func setUp() {
super.setUp()
let app = XCUIApplication()
app.launchArguments += ["-anargument", "false","-anotherargument","true"]
app.launch()
}
}
app code
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
print("All arguments: \(NSProcessInfo.processInfo().arguments)\n\n")
print("anargument: \(NSUserDefaults.standardUserDefaults().boolForKey("anargument"))")
print("anotherargument: \(NSUserDefaults.standardUserDefaults().boolForKey("anotherargument"))")
return true
}
app output when launched from ui test:
All arguments: ["/...../AnApp.app/UITest", "-anargument", "false", "-anotherargument", "true"]
anargument: false
anotherargument: true
UI Testing runs in a separate process from your app. There is currently, as of Xcode 7.1.1, no way to interact directly with the production app's code from the framework.
Every interaction must route through accessibility. This means that you could wire up a button that executed code in your app, then have the tests call that button. This is obviously not scalable and I would recommend against it.
Maybe there is another way to achieve your goals? What exactly are you trying to accomplish?
I'm thinking of passing an environment variable to the app when testing which launches an embedded HTTP server. Then I can communicate with the app through the server. Crazy, right? And yet, I can't believe nobody has done this yet.
My biggest concern with this approach is that the embedded server will be in the production app. I'm not sure if that is a problem, or if there's a simple way to only include it when running UI tests.
I'm working with the tvOS beta 3 and trying to do some basic debugging on the tvml/tvjs side of things.
Messages logged via console.log(...) in my js files don't appear in the main Xcode output window.
Is there somewhere else I can find these messages or a setting which needs to be configured?
You should actually use the debug console in Safari. (The developer forum suggests you use Safari 9 and upgrade to El Capitan, both of which I have so haven't been able to test with inferior version)
Open Safari > Develop menu > Simulator
Your app name should appear here once and from there you can use the console.
Give it a few seconds to appear, it's not always instantaneous.
You must give a name to the Bundle Identifier in General/Identity (com.yourcompany.appname) to appear the app in the developers tool.
If you are developing a hybrid application (TVML/TVJS + Swift) with TVMLKitchen you can implement a logging function in Swift and use it in the TVJS code. For my projects I use the following code:
Kitchen.appController.evaluateInJavaScriptContext({context in
let printInJS : #convention(block) (NSString!) -> Void = {
(string : NSString!) -> Void in
print("Log: \(string)\n")
}
context.setObject(unsafeBitCast(printInJS, AnyObject.self), forKeyedSubscript: "printInJS")
})
I want to integrate some voice commands in my windows phone 8.1 app.
The first thing I want to do is to open my app by a voice command and navigate to a certain page.
According to MSDN article Quickstart: Voice commands (XAML) I can use the override of protected virtual void OnActivated(IActivatedEventArgs args) method in App.xaml.cs to meet my requirements. But it does'nt work the way I though it would!
I have the method with the following structure:
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.VoiceCommand)
{
var commandArgs = args as VoiceCommandActivatedEventArgs;
if (commandArgs != null)
{
// ... some logic here
}
}
}
The problem is when I'm activating my app by saying "Open 'name of my app' [optional words]" the app opens but the Activated event never fires! The app opens and OnLaunched event fires. So I can't even enter the OnActivated method.
Does anyone know the problem? Why can't I enter OnActivated method using voice commands?
P.S. I tried it with a simulator as well as with a real device.
you can see this article,
http://t.co/Q5hRxRPvwR
is in spanish, but you will understand.
After you install the app and run it, the xml should be installed, like said in documentation.
After ask to cortana "What can I say?" it will show all you can said, and the apps that supports cortana. Choose you app and you will see what you can say for your app, like
If you say what your app can listen, your app will be activated.
in my windows phone 8 application i am using custom uri association to launch another application through my phone.
i.e
await Windows.System.Launcher.LaunchUriAsync(new Uri("sixtag:"));
but my app is not able to get certified for store because of this. the testing team tells that you app terminates unexpectedly while executing this.
now, i don't know how to deal with this.
is there any way to throw exception if the app which i am launching is not installed on phone ?
or i should try something else so my task gets accomplished and app gets certified for store as well.
You do not need to wrap your launch in try/catch or check for success as described in the other answers. As soon as you call LaunchUriAsync, the platform takes over and will automatically handle the possibility of no app being installed by asking the user if she wishes to search in the store.
A couple of things to double-check:
1) Ensure that you can successfully back into your app following the navigation to sixtag.
2) Ensure that your call to LaunchUriAsync is the direct result of a user action (eg. tapping a button)
try
{
await Windows.System.Launcher.LaunchUriAsync(new Uri("sixtag:"));
}
catch
{
MessageBox.Show("please install Sixtag from the app store","AppMissing", MessageBoxButton.OK);
}
you can perhaps display another button and on clicking directly navigate to the app store. See if this solves your problem. Do vote it up if it does :)
You are needed to handle that as shown here . Also Read out Remarks given there.
As windows phone 8 provides us with this method for programmatically terminate an app, will there be any issue while app submission if we use this in app for terminating a page while there is no backentry in the navigation history?
There won't be any issue in certification when using this call, but make sure you have saved all data in your app when calling this, because this call effectively kills your app immediately - ApplicationClosing even handler won't be raised after it!
Why would you call Application.Terminate when navigating back with an empty back stack? Just let the app close itself. Seems a bit pointless to me to overuse Application.Terminate().
I can't say much about the new Terminate method, but I do have an app (NOTE: Not a game) that does the following at certain points
private void Kill()
{
new Microsoft.Xna.Framework.Game().Exit();
}
This app passed certification without any problems. This was an app for both WP7 and WP8 so I did not have the ability to use Terminate().