Any way to get a reference to the currently display iOSView?

I’m using an encrypted third party iOS class to present some images/videos. Works great, but I want to disable the share button in the view.

I’m trying to find a way to get access to the iOSView object to see what can be done, but there’s no Runtime/Windows list, and App.CurrentScreen does not return the item (even after a delay) possibly because it’s displayed as a full screen modal.

You mean other than Self or Self.Handle?

I don’t have access to the class itself or the view it presents since it’s in an encrypted class. I use ThatClass.Show and it brings up the view.

I can’t add code to the class because of the encryption, so I was hoping from somewhere else I could access the front most view, similar to how Window works on desktop.

You may be able to get the Self reference by creating a subclass and using that instead of the encrypted class. Depends on many things however if this is possible.

A good idea, but doesn’t work here. The constructor can only be called from within the class, and the method is a shared method that creates the iOSView, so I don’t have a reference to the class object itself or the view really.

Yeah I was afraid that might be the case. Using iOSKit (only needed the UIKit and Foundation folders) I was able to get the internal handle to the root and presented controllers (the later of which should be what a modal Xojo View is represented by) like so, on a View with a Button containing this code and an empty TextArea:

declare function sharedApplication lib UIKitLib selector "sharedApplication" (clsRef as ptr) as ptr
declare function keyWindow lib UIKitLib selector "keyWindow" (obj_id as ptr) as ptr
declare function rootViewCtrlr lib UIKitLib selector "rootViewController" (obj_id as ptr) as ptr
declare function subviews lib UIKitLib selector "subviews" (obj_id as ptr) as ptr
declare function lastObject lib FoundationLib selector "lastObject" (obj_id as Ptr) as Ptr

dim win as ptr = keyWindow(sharedApplication(NSClassFromString("UIApplication")))
dim topView as UIView = new UIView(lastObject(subviews(win)))
dim rootController as UIViewController = new UIViewController(rootViewCtrlr(win))
dim topController as UIViewController = rootController.presentedViewController
dim lines() as text

lines.Append(topController.title)
lines.Append(" > ")
lines.Append(rootController.title)
TextArea1.Text = text.Join(lines, "")

Depends on what you want to actually do with it if this would be useful.

Have you tried…

App.CurrentScreen.Content

Content can be a view, tab bar or split view, so you’d have to check first, but that should get you what you want.

http://documentation.xojo.com/api/deprecated/iosscreen.html#iosscreen-content

[quote=427162:@Isaac Raway]Yeah I was afraid that might be the case. Using iOSKit (only needed the UIKit and Foundation folders) I was able to get the internal handle to the root and presented controllers (the later of which should be what a modal Xojo View is represented by) like so, on a View with a Button containing this code and an empty TextArea:

declare function sharedApplication lib UIKitLib selector "sharedApplication" (clsRef as ptr) as ptr
declare function keyWindow lib UIKitLib selector "keyWindow" (obj_id as ptr) as ptr
declare function rootViewCtrlr lib UIKitLib selector "rootViewController" (obj_id as ptr) as ptr
declare function subviews lib UIKitLib selector "subviews" (obj_id as ptr) as ptr
declare function lastObject lib FoundationLib selector "lastObject" (obj_id as Ptr) as Ptr

dim win as ptr = keyWindow(sharedApplication(NSClassFromString("UIApplication")))
dim topView as UIView = new UIView(lastObject(subviews(win)))
dim rootController as UIViewController = new UIViewController(rootViewCtrlr(win))
dim topController as UIViewController = rootController.presentedViewController
dim lines() as text

lines.Append(topController.title)
lines.Append(" > ")
lines.Append(rootController.title)
TextArea1.Text = text.Join(lines, "")

Depends on what you want to actually do with it if this would be useful.[/quote]
Thank you Isaac. This is getting close as it is correctly listing out the titles and topController is the one I’m going for. Now to figure out how to get an iOSView from that reference. Haven’t used much of iOSKit.

[quote=427170:@Greg O’Lone]Have you tried…

App.CurrentScreen.Content

Content can be a view, tab bar or split view, so you’d have to check first, but that should get you what you want.

http://documentation.xojo.com/api/deprecated/iosscreen.html#iosscreen-content[/quote]

Thanks Greg. This simply shows the most recent view that was pushed to in the main view controller. It’s not doing anything to get the Modal view that is presented by the encrypted class.

You will never be able to get an iOSView from Ptr (topView as UIView in the previous code).
Xojo would need a function to cycle through all iOSViews in memory for this.

Could you share a screenshot of the view ?
Do you know if the share button is an iOSToolbutton, or just a regular button in the view?

After the code provided by Isaac, something like this might help:

[code]Declare function navigationItem lib UIKitLib selector “navigationItem” (obj as ptr) as ptr
Declare sub setRightBarButtonItem lib UIKitLib selector “setRightBarButtonItem” (obj as ptr, value as ptr)

Dim navItem as ptr = navigationItem(topController)
setRightBarButtonItem(navItem, nil)[/code]

The above assumes that the share button is set in the View’s RightNavigationToolBar.

If it isn’t, you might need to use Revealapp.com to investigate the view hierarchy.

@Tom Iwaniec
Any chance you could tell us which component this is?

I’m using Antonio Rinaldi’s (wonderful) ARPreviewController (https://www.falcosoftware.com/xojo/) which most likely is using a modal QLPreviewController.

The share button is in different locations on iPhone (bottom) and iPad (top right) but I only need this working on iPad. Here’s a screenshot of the view.

@Jeremie Leroy Thanks for that, I tried it but it just causes the app to crash from this line:

Dim navItem as ptr = navigationItem(topController)

Did you try contacting @Antonio Rinaldi to get an option to remove the share button?

I really think that would be the easiest way to do it.

Yep we’ve been in contact but it’s not something that can easily be removed since it’s built in to the QLPreviewController, and it probably has to be hackily removed. Apparently according to other people on the internet trying to remove it, the button also returns periodically if you remove it. Not the sort of option you could add into a class you’re selling to others.

Hi Tom, I’ve found a working solution.
It will disable the share button (a better and working way than the ones on the net)
Tomorrow I will publish an update.

In any case, it’s an hack, since iOS add the button in an unknown point and as side effect it will be disabled after the animation so for a little moment it will be shown as enabled.
In any other way the results are inconsistent

Thanks Antonio that’s great to hear. Was hoping I’d be able to find a workaround for it on my own to save you some work since you’ve already been so responsive with everything else I’ve needed.

Just to clarify:
The iOS system creates when it needs the button, so very hack to remove or disable it , as suggested on the net, will not work.

You can disable it, but then, ie for complex document, you will have again.
So I decided to control the action:
when you choose to have the button disabled, as soon you click on it, it will do nothing (better it will become disabled).
One solution for all the different situations (position, document kind)
… and, obviously, with the easiest way to use it in your app.

ps The update will be soon on line.

the new release is online

Thanks Antonio this solves the problem without having to full solve my attempted workaround from the original post. Thank you for your quick response and support.