Keyboard doesn't close after Cancel button SearchBar Ionic 2 - ios

I am implementing searchbar in Ionic 2. When I run the app in iOS, in simulator or on a real device it doesn't work properly. When I click Cancel the keyboard closes at first and then reopens again. The searchbar, still has the cursor in it.
This what I have done.
.html
<ion-searchbar
placeholder = "Kerko"
(keyup.enter)="search(q.value)"
[showCancelButton]="true"
(ionCancel)="reset($event)"
></ion-searchbar>
.ts
constructor(private navCtrl:NavController,
public keyboard: Keyboard,
private platform: Platform) {
}
search(q: string) {
console.log(q);
this.navCtrl.push(SearchPage, {"query": q});
}
reset(event) {
this.keyboard.close();
}
Any idea how to solve this?

Related

How to dismiss keyboard on change app lifecycle state

How to dismiss keyboard in flutter when I change the app using task list or if I pressed home button on iOS and double click home button and got back to app
You can reproducer the problem by doing the follow:
focus Textfield so keyboard will appear and double press home button on iPhone to switch to another app using task list then again double press home button and switch back to your app!
The keyboard stays and not responding
I tried the following :
#override
void didChangeAppLifecycleState(AppLifecycleState state) {
print('state = $state');
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
currentFocus.focusedChild!.unfocus();
}
SystemChannels.textInput.invokeMethod('TextInput.hide');
}

How to return to today extension from app

When the user taps the today extension it opens the app where they can modify its settings. But when the app is exited, the user is returned to the home screen. Is there any way I return focus to the today extension so the user can view the changes immediately? Or is this just not possible in iOS?
I recommend making a button to go to the app. Or add transition functionality after applying settings.
like this
var instagramHooks = "instagram://user?username=johndoe"
var instagramUrl = NSURL(string: instagramHooks)
if UIApplication.sharedApplication().canOpenURL(instagramUrl!)
{
UIApplication.sharedApplication().openURL(instagramUrl!)
} else {
//redirect to safari because the user doesn't have Instagram
UIApplication.sharedApplication().openURL(NSURL(string: "http://instagram.com/")!)
}
User can click on the top left button to return if the application has been opened from another application. You can update the data on his return.

How should we put custom UIButton in google maps app?

By clicking on a button am navigating to google maps app, and there am showing directions from one location to another location.
here is the code which i wrote in button
#IBAction func movetonextclass() {
if UIApplication.shared.canOpenURL(URL(string: "comgooglemaps://")!) {
let googleMapUrlString: String = "comgooglemaps://?saddr=&daddr=\(CDouble(startLat)),\(CDouble(startLong))&mode=driving"
UIApplication.shared.openURL(URL(string: googleMapUrlString)!)
}
else {
let googleMapUrlString: String = "http://maps.google.com/maps?f=d,&daddr=\(CDouble(stopLat)),\(CDouble(stopLong))"
UIApplication.shared.openURL(URL(string: googleMapUrlString)!)
}
}
now i would like to display a custom UIButton in that screen.
if i click on that button, i should navigate to my own app
how should i put a button in google maps screen?
could any one help me with this
You cannot add anything in not your application, but actually from ios 9, when you open an another app when your app in active state you can back to previous application by tapping at the top left corner.

How to call UIAccessibilityRequestGuidedAccessSession()

I want to create an app that has a button to lock, and another button to unlock.
Lock - This button will lock device. Only this app's screen will show nothing else will be accessible even after restart same screen will show up. Home button, gestures will get disabled similar to single app mode.
Unlock - This will unlock device and switch to normal behavior of device.
Here's what I tried:
#IBAction func lock(sender: UIButton)
{
UIAccessibilityRequestGuidedAccessSession(true) {
success in
println("\(success)") // success is false
}
}
#IBAction func unlock(sender: UIButton)
{
UIAccessibilityRequestGuidedAccessSession(false) {
success in
println("\(success)") // success is false
}
}
When I lock it and then press the home button, it goes home. Am I doing anything wrong? What can I do to fix it?
P.S. I'm new to swift coming from Objective-c

Handle iOS home button press in as3

I need help detecting and dealing with the home button being pressed on a iPhone/iPod Touch running an AIR app. I tried
NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);
function handleKeys(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.HOME) {
//do something
}
}
without luck. Any ideas? Specifically, I want to prevent the app from closing when the home button is pressed.
import flash.events.Event;
addEventListener(Event.ACTIVATE, activateListener);
addEventListener(Event.DEACTIVATE, deactivateListener);
private function activateListener(e:Event):void{
//do something when awakened
}
private function deactivateListener(e:Event):void{
//do something when home button is pressed.
}

Resources