This question already has answers here:
OSX Swift open URL in default browser
(8 answers)
Closed 5 years ago.
Looking to open a link via UIApplication.shared.open in Swift4, Xcode9, I'm trying to use a completion block as is standard now, the most common stackoverflow answer is:
UIApplication.shared.open(url, options: [:],
completionHandler: {
(success) in
print("returned")
})
You don't have to return any value and your code should work as it is. You just need to check if the browser was launched or not as follow:
let url = URL(string: "https://www.google.com")!
UIApplication.shared.open(url) { success in
if success {
print("browser successfuly opened")
}
}
Related
This question already has answers here:
Should I avoid 'async void' event handlers?
(4 answers)
Closed 2 years ago.
I am getting myself confused about async void and button handlers. I heard in a video tutorial that it was not wise to use async void. I have reviewed these questions:
question
question
In many answers it does actually use this syntax. Thus my confusion. 🧐
Here is my handler:
async private void InstallStyleButton_Clicked(object sender, EventArgs e)
{
var customFileType =
new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>
{
{DevicePlatform.macOS, new[] {"xsl"} }
});
var pickResult = await FilePicker.PickAsync(new PickOptions
{
FileTypes = customFileType,
PickerTitle = "Select template to install"
});
if(pickResult != null)
{
// Build target path
string targetFile = Path.Combine("/Users/Shared/VisitsRota.MacOS/Styles", pickResult.FileName);
// OK to install?
if(!File.Exists(targetFile))
{
// Install
File.Copy(pickResult.FullPath, targetFile);
// Add it
StylesPicker.ItemsSource.Add(pickResult.FileName);
// Select it
StylesPicker.SelectedItem = pickResult.FileName;
}
}
}
I realise it is not a good idea to hardcode the folder path and I will eventually get around to that. Other than that, my handler appears to operate fine on my development MacBook Pro when I try it.
Is my use of async void with the button handler ok? And if not, how should my handler be adjusted?
I found this link where it states:
To summarize this first guideline, you should prefer async Task to async void. Async Task methods enable easier error-handling, composability and testability. The exception to this guideline is asynchronous event handlers, which must return void.
So my code is OK.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Im calling this funcion in many tests. How can i put that in commands.js file and call it where needed
Following Cypress guide. Cypress recommendation is to use commands.js
Documentation link :
[https://docs.cypress.io/api/cypress-api/custom-commands.html#Syntax][1]
You can add CategoryNumber() like this. Go to Support Folder. You will see Command.js
Cypress.Command.add('CategoryNumber, ()=> {
ACTUAL FUNCTION Code
}
How to call?
Go to test definition and call as cy.CategoryNumber()
example function :
Cypress.Commands.overwrite('visit', (originalFn, url, options) => {
const domain = Cypress.env('BASE_DOMAIN')
if (domain === '...') {
url = '...' }
if (options.something === 'else') {
url = '...' }
// originalFn is the existing visit command that you need to call
// and it will receive whatever you pass in here. // // make sure
to add a return here! return originalFn(url, options)
})
This question already has answers here:
Http Status Code in Android Volley when error.networkResponse is null
(8 answers)
Closed 6 years ago.
My app uses volley library for networking operation. I want to get the response code (that may be 200 or 401) inside onResponse() method. How can i achieve that?
you can make a custom request and override:
#Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {
if (response.statusCode == 200) {
//do smth
} else if (response.statusCode == 401) {
//do smth else
}
return super.parseNetworkResponse(response);
}
this way you will still receive the same data in your callbacks but special cases typical for the request you can handle within the request itself.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Why HttpContext.Current.Session is null in Global.asax?
I am developing a MVC3 project (Razor).
I added a variable to my session in some Controller/Action (different per user).
I want to access this variable in Application_AuthenticateRequest method (global.asax).
This exception happened:
Session state is not available in this context.
Sample Project
For startes, see https://stackoverflow.com/a/4185982/717732
The whole point is that Session is not available and simply will never be available at this point of time: and by 'time' I mean 'when this event is fired'.
Read the lifecycle for example at devproconnections.com/article/aspnet2/
The Session object is prepared much later: during the AcquireRequestState event. This is the first 'time' when you can access the Session statebag and investigate it.
Thanks quetzalcoatl,
This is true.
try
{
if (Session != null)
{
if (Session["mys"] != null)
{
//Error
string s = HttpContext.Current.Session["mys"].ToString();
}
else
{
Response.Redirect("~/Home/Index");
Response.End();
}
}
}
catch {
Response.Redirect("~/Home/Index");
Response.End();
}
This question already has answers here:
How do I return the response from an asynchronous call?
(41 answers)
Closed 8 years ago.
function getsession(){
var data = $.get('../session', function(data)
{
return data;
});
return data;
}
alert(getsession());
returns [object Object]
I want it to return the data from the GET.
try this instead
function getAndProccessSession(){
$.get('../session', function(returnedSessionData)
{
console.log(returnedSessionData);
});
}
Since the function passed $.get is executed asynchronously after the HTTP request is finished, you can't get a return variable.
After $("#openSession").append(data), you could also alert(data).
if you want to see the data and your using firefox maybe some others you can use
alert(getsession().toSource());
that way you can see the object that your getting back but if you know the data items you can target them direct
alert(getsession().someItemInTheObject);
if you are using google chrome you can do a console.log(getsession()) within your code and then press ctr+shift+c to open google chrome dev tools, then go to the console tab, you can see the object there and you can click it to view its internal properties values