How to programmatically present the WebKit inspector for a WKWebView? - swift

Is there a way to programmatically present the WebKit inspector for a WKWebView? I am aware of how to enable the inspector for a WKWebView but what I would like to do is, similar to what is described here for a WebView, to be able to also directly pop it up on the screen programmatically from my own code. Use of private APIs and other hacks are naturally OK for me to accomplish, as this is only for debugging purposes.
The use case I have for this in my debugging flow is a WKWebView in my desktop based app where the right-click events that would usually allow for a context menu to be used for something else app specific.
As a workaround, would be happy with any means not involving right-clicking in the web view itself to bring up the inspector.

Reclaiming the right-click, eh? Interesting.
I had to plumb a large portion of WKWebKit2 C API headers into my swift app's build.
Roughly, to pull up the JS console:
WKInspectorShowConsole(WKPageGetInspector((wkwebview.subviews.first as! WKView).pageRef))
The gory details:
https://github.com/kfix/MacPin/commit/5fed6cb01ab88170f1387122748f8c4ae9e2cab5#diff-c5ffd49d5bf2cde5e056621f9ab14545R426
You need to pull in WKBase.h and WKView+Privates.h

Related

How to check which class/UIViewController is executing while testing on device on Xcode?

Recently I have been working on an old swift project built in back in 2015. Its really difficult to find which ViewController is executing currently because of the naming convention, usage of really massive storyboard(I feel terrified to even go to the main.storyboard) and various reason like usage of different language. Of course I can find it but it takes long. I was thinking if there is any way like when I run the project on a device and navigate to different page is there any way to see in the console which ViewController is executing ?
There is a quick way to find what view controller you are on when you are running your app.
1) Launch your app on the device or simulator.
2) Go into Xcode and tap this button:
3) This will open the Debug View Hierarchy. Click on the phone and you will see all the elements in the top bar. You can also see a hierarchy on the left-hand side. In here, you can click down and you will see the name of the view controller on screen.
Using the debugger after putting a breakpoint where you prefer you can write this and press return.
Swift 4.x
po UIApplication.shared.keyWindow?.rootViewController?.value(forKey: "_printHierarchy")
This method is a private API, thus you cannot use on production code, just use it in debug or from the debugger console.
I think it is better to see in debug area for your current viewcontroller named self, you get all information from there open the dropdown and and see you need to put break point in your viewController init method or where you want to debug, However you want to know programatically which is you current viewController you can get it by
appDelegate.window.currentViewController()
If you need which ViewController is Pushed or presented you can get from the above code but the case will be different if you are using the Slidemenu controller, I mean it is totally depends on how you have started navigation and which navigation controller is currently is use.
Can you briefly describe why you need current ViewController so i can help you further.

Swift - disable accessibility voiceover?

I was curious if there was a way to disable the voiceover accessibility (or any other type of accessibility feature for that matter - like hear aids, captioning, etc.) in swift?
Essentially, I'm trying to build an application that has a very high likelihood of being used by people with visual impairments and I've tailored my entire application for such people.
But given that this target group may have the voiceover accessibility feature on, can I disable that only within my application?
I see that on xcode 7, underneath the identity inspector, there is a section for accessibility (picture below) and I tried unchecking that box but it seems like voiceover and the highlighting focus feature are still in effect. Let me know if you have any suggestions or comments, thanks.
You can set
element.accessibilityTraits = UIAccessibilityTraitAllowsDirectInteraction
on any elements that you want to provide custom audio/interactions for.
This can also be accomplished in storyboard (See photo).
I came across this thread because I was trying to do this for on a game scene tucked inside of a view container. To get it to work, I was able to set
.accessibilityTraits = UIAccessibilityTraitAllowsDirectInteraction
on each SKNode that had custom accessibility created for it, and then was able to select the proper options (again see screenshot) on the SKView -> View in Storyboard to allow the game screen to work.

iPhone/iPad: Universal App and InAppSettingsKit

I have a application which is a universal application. On iPhone, it's a Tab Bar application and on iPad its a Split View app. For settings, I really wanted to include the three most important settings in my application, and then launch the Settings Application on demand for minor settings (but Apple screwed us there). So I'm trying to integrate InAppSettingsKit.
Because the application is a universal binary, InAppSettingsKit must be installed in Shared/. Otherwise I will get problems with duplicate symbols (or I have to duplicate and rename everything with *_iPhone and *_iPad).
I'm trying to cut-in InAppSettingsKit on the iPhone. Because its a tab view, there is no NavigationController as IASK expects (so a tap does nothing except highlight the row cell). So the library will need some modifications. In addition, when I tested a purely iPad cut-in, IASK would SIGABRT because it expected a tool bar (IIRC).
The README only has a link to http://www.inappsettingskit.com, which looks like a lot of programmer related marketing. There are no Universal App samples, and the two samples provided are very basic (not reflecting the needs of a Tab Bar/Split View app). In addition, I have not found a place to ask questions (github does not appear to have a bulletin board system [1]) and there does not appear to be contact information.
Has anyone successfully used InAppSettingsKit in a Universal App? If so, was sharing the best method, or was duplicating files and renaming the best method. Was it worth the effort to debug and modify someone else's work in a vacuum? If someone have a better recommendation, I would love to hear it.
[1] https://github.com/futuretap/InAppSettingsKit
First of all, there's an "Issues" area on the GitHub page where you can ask question, too. We don't give individual advice because we wanna avoid duplicate work for a voluntary project.
I don't see why you should need to modify InAppSettingsKit at all depending on whether it's used in a tab bar or split view controller.
Take a look at the sample project where we integrate IASK into a tab bar, a navigation controller and a modal view controller.
Other than that, I'm afraid, I don't have specific advice how to integrate it into a Universal binary.

How to implement iPhone TitleBar in Android

You know in iPhone, The four components of a typical iPhone application are
a title bar,
a navigation list,
a destination page,
and a button bar.
for The Title Bar
The title bar includes the following elements:
Back button:
Screen title:
Command button:
My question comes, although i can use UI framework tool, such as:
Phonegap,
iui,
jtquery
to develop web app, but i can't display the TitleBar effect in Android,
i can't use below code in Android:
meta content="yes" name="apple-mobile-web-app-capable"
Actually, the above can work in Apple Safari Browser, but I can't use Safari to display our Android Project, which is i don't want to see.
Does anyone know how to fulfill this effect in Android, please help me, your help will be great appreciated.
to
"It's unclear if you developing a native android application or a webapp.
– alexanderblom yesterday"
sorry that i forget to mention, i want to develop a iphone-webapp-style application in Android. Since it's too difficult, i want to use iWebkit, but it seems only work in apple iPhone OS or Safari which contain the specific engine to display the beautiful layout, like below:( -_-! i am new so i can't post images here)
(source: appshopper.com)
If I'm not mistaken, if you want to custom in any way the title bar at the top of your screen, you have to do several things :
First, read this thread about titlebar customisation, as it's quite detailled.
Then, you have to add a few more things to it to match your requirements, all in the same xml file which will be your titlebar.xml:
-a button, on which listener you assign the same keyEvent as the normal back key of every android phone.
-a textview for whatever title you want to put in.
-a button for the command button, for whatever it does in Iphone (if you tell me what it does, maybe i'll be able to give more details)
Then, as I take it, you want to have it available on all your pages, without having to request titlebar customization on every activity, I would recommend you to use the same trick as I did : Define a superclass, which all your activities will extend.
then you you requestwindowfeatures in this class, and do all your customization in this one.Finnaly, You just have to call the variable of your titlebar textview in the oncreate of all your subclasses to assign the string you want on each page. If your string is generated dynamically from, lets say a file name you load from the internetv in a background thread, you will need to define a handler to the main thread as you can't update a view from another thread than the one that has created it.
Hopes that helps. If you have any question about that, feel free to ask, i'll keep an eye on your topic, because I had quite a pain to make my titlebar work properly.
good luck

iPhone: Is there a pre-made UISettingsView?

On startup, if the user hasn't done any setting of NSUserDefaults, I want my main view to do a flipside view that brings up the same stuff that shows up in the Settings app.
Is there an API for instantiating the same controller that Settings uses, or will I have to reimplement a table view and controller myself?
This website hosts the 'MySettings' API which is a nice toolkit that encapsulates various Settings features (switches, choices, etc) all in a declarative (plist-based) API.
You have to code the ui elements yourself if you wish to make the perferences available within your app. The utility template in xcode gives you a starting point by making a flipview available.
Check out Craig Hockenberry's Generic Table Views, which make it really easy to set up a Settings-like table view.