Detecting Bluetooth Keyboard in iPad App - ios

In my app I am having a customer info form on which there are a number of text fields I have used, now when a user edits any field I need to move whole view up so that the editing text field won't get under iPad's internal keyboard and this is working fine.
Now the client wants to use external Bluetooth keyboard for filling this form. Once this external keyboard is connected with iPad then in the app when editing any text field won't show internal keyboard as the external is connected and in this case whole view needs to be on the page and no need to move it up.
But when I edit text field it still goes up without showing internal keyboard on the screen and this leaves half of the screen blank as it moves whole view up.
For this I have tried some ways like enabling internal keyboard show/hide notifications but these notification only gets called when external keyboard is not connected and this is not helping me.
Also have tried with ExternalAccessory framework, but it wont detect the bluetooth connected keyboard also tried with EADemo to detect external keyboard and its not detecting external keyboard but it detects credit card swiper connected trough dock.
If anyone here has gone through this functionality or knows anything related with this, then please let me know.

#SpySudhir --
Logic A:
have a bool variable in some file which will return yes/no value when the keyboard is external or internal.
On the basis of the bool value returned call the animation function.
Logic B:
Listen to the keyboard notification using NSNotificationCenter.
Notifications like will,show,hide notification put an NSLog over their and see which one of them is getting called.
If external board is connected the willShow method does not gets called. so in this case can we can do some work around and set the bool value to no or we can have a counter and check it every time if its value is increased by one or is same something like this.

You should not move the view up when field gets focus - you should only move the view up as a response to a UIKeyboardDidShowNotification. The system takes care of the rest for you.

Related

Intecept touch on an ad view, present alert, go forward based on response

I've got an app which uses Google Mobile Ads SDK to display ads in a queue. I want to be able to detect when a user clicks on an ad (not just touches it while scrolling). If I detect that they've clicked, I'd like to be able to show an alert notifying the user that they will be navigating away from the app if they continue, giving them two options - one to continue and another to cancel. If they choose continue then I want to not interrupt the default action that happens when they click on the ad. If they choose to cancel, I want nothing to happen.
I've read through Apple's document: https://developer.apple.com/library/content/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/multitouch_background/multitouch_background.html#//apple_ref/doc/uid/TP40009541-CH5-SW9
and have tried overriding hitTest:withEvent: on a container view for the actual ad view. This allowed me to detect the touch but I can't tell if is an actual touch or just the user scrolling. Also, I can't synchronously stop the return of hitTest with an alert. The function finishes before the response comes back from the alert (which is expected).
I've also researched synthesizing touch events but it seems that is highly discouraged and maybe the only way to do it is using private APIs which I don't want to do.
I feel like I'm close here but still missing some pieces, assuming what I'm trying to do is even possible.
For the first part of your problem you could just create a clear UIButton with no text on top of the view that contains the ads, that way you can intercept the touch without having to worry about scrolling. I think using the responder chain is the wrong way to go about it because you want an event that requires a response from the user to trigger between when you detect the touch and when you want the ad event to fire, so there is no way to pause that even and allow it to continue at a later time.
I'm not sure about the second part of your problem as I don't have much experience with Google Ads but I suspect they have closed off any methods which would allow you to procedurally fire off the ad event without user interaction as it would open the system up to abuse. That is just my suspicion tho and it may be wrong. If I am wrong then avenues worth exploring would be calling sendActionsForControlEvents on any buttons within the Google Ads framework if they are exposed. If they are not exposed they you may be able to recursively search through child views of the top level view you do have access to and check if they are of type UIButton. It's possible they don't even use UIButton so this may be a dead end.
It sounds like the problem you're really trying to solve is preventing accidental taps on ads when a user is scrolling. Assuming you're using a UIScrollView, you can disable user interaction on the GADBannerView when the user is scrolling and enable user interaction once the user has stopped scrolling.
For example:
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
banner.isUserInteractionEnabled = false
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
banner.isUserInteractionEnabled = true
}
You may have to experiment with different UIScrollViewDelegate methods to see which ones work for you. Here's a complete list: UIScrollViewDelegate.

How does iMessage preserve viewController state after view disappears?

I observed that iMessage preserves last typed message in a chat even if I move to another chat and come back to it.
For eg. I am in Chat1 and typing. Then without sending the message I move to Chat2 and then come back to Chat1. Last typed message is still there.
If I understand correctly, when I press back button in Chat1, it should execute viewWillDisappear which should destroy all local elements.
Then how is last typed message still there?
iMessage is not the only app which does it. Whatsapp also does it. Even you open a chat in whatsapp scroll to older message->go back->and come again on the same chat. You will see the old state of chat.
The Recommended way to do it is App State Restoration if you want to store the whole state of your controller with more UI elements and values.
You can check following tutorial available for this..
https://www.raywenderlich.com/117471/state-restoration-tutorial
http://useyourloaf.com/blog/state-preservation-and-restoration/

iOS Swift Briefly Display Info

I want to have some information drop down from the top of a view, stay on the screen for a second or two, and then go back up out of the view. I have search for displaying notifications and/or banners. All I get is either push notifications (which I don't need to use) or iAds banners.
I'm working on a barcode scanning app and I want to briefly show the value of the barcode shown without requiring the user to tap on anything. How can I accomplish this?
Don't use notifications and banners, because that might not work: the user can turn them off. In any case this is not a notification of anything, so it's a misuse of notifications.
Just do what you described, yourself: animate a view onto the screen, and then (in the animation's completion handler) use delayed performance to animate the view right back off the screen after a short delay.
You should use a view which manages its own state (INCOMING, STAY PUT, OUTGOING). This way you can reduce the memory footprint and many other bugs in the process. I coded something for a similar process. Check it out

iOS 6.1.5 UITextField - text not populating

My customer has a POS (Enterprise) app that was working fine on iPod6.1.3. Some of the devices were upgraded to 6.1.5 last week and began exhibiting a problem with taps on the keyboard not populating the UITextField. Unfortunately it is an intermittent problem and I do not have reliable steps to replicate, but I have seen it happen on a 6.1.5. device while running under the debugger. Here's what I know:
User taps on any of 7 UITextFields on the view. Keyboard slides up from bottom. Cursor starts blinking in the field.
User taps any key (including return). The key popover shows the key being pressed. Nothing appears in the UITextField.
Once the problem starts, it will persist until I quit the app (in this case, the app really quits with an exit(0) - required due to credit card security). Running the app again will most likely work correctly.
In the debugger, when things are working correctly I get callbacks to textFieldShouldBeginEditing:, textFieldDidEndEditing:, textFieldShouldReturn:, and textField:shouldChangeCharactersInRange:replacementString: as expected. When things don't work, I DO get callbacks for textFieldShouldBeginEditing: and textFieldDidEndEditing:, but I DO NOT get call backs for textFieldShouldReturn:, and textField:shouldChangeCharactersInRange:replacementString:. I checked the delegate for the UITextField in the shouldBegin and DidEnd methods - they are of course set to self.
Again, this behavior is new, and only in iOS6.1.5. There is nothing "fancy" going on in the view controller.
Any help would be appreciated.

VOIP App window (in foreground) blocked from receiving user input during Active Cellular Call

During an active VOIP call, my app is put into the background when an incoming cellular call is received and answered. If, while on the cellular call, I bring my app back to the foreground the app view appears but is unresponsive. The "Touch to return to call" banner appears at the top of the view in green but the app view appears as if there is a darker transparent window overlaid on top of it preventing the view from receiving input. If I put my app into the background, bring another app to the foreground and then bring my app back to the foreground everything works as expected so the problem seems to be specific to active cell calls and/or the green banner only? In Settings->Notifications->Phone I tried turning Notification Center OFF and Alert Style NONE in the hopes of removing the banner to see if the problem still exists but these settings do not effect that banner. In addtion to the App window appearing to have a transparent window overlaid on it, if I touch the window I'm able to drag the entire app window (or view) in all directions (up down side to side) and it has a bounce effect (like tableview vertical scroll) when I release it.
If I dont know the problem I cannot fix it (:
Thanks..
Are you sure there's no view being added on top your view which might be intercepting all your events? My second guess would've been that your app received a memory warning and unloaded a bunch of views. However, that's not very likely since you still see all the views.
I don't know what you really mean to "bring your app back to the foreground",but I can tell you for sure that you cannot call in the same thread the UI and the incoming call, so for situations like this when you want to render some view during a call you can try something like this:
public void InvokeGUIThread(Action action)
{
Dispatcher.Invoke(action);
}
For example if you want to set a text in a textblock do something like this:
InvokeGUIThread(() =>
{
textBlockSome.Text = e.Item.ToString();
});

Resources