Is there any method available in WebKit framework which tells that user has clicked on a particular button of the the web page or user clicked on some link.I want to perform some action when user clicks on a button of a webpage,but i am not able to identify that that user clicked on a button.I searched a lot but i am not able to find such method.Please help!
Set the UI delegate and the policy delegate via [webView setUIDelegate:] and [webView setPolicyDelegate:], and implement the delegate methods explained in Web UI delegate protocol reference and in Web Policy delegate protocol reference.
Look for webView:mouseDidMoveOverElement:modifierFlags: in the UI delegate and webView:decidePolicyForNavigationAction:request:frame:decisionListener: in the policy delegate to achieve what you want to do.
Related
I have a table on my main watch interface. Upon user selection, a 2nd interface will show and display more details about the user picked item.
I'm thinking about adding a button to this 2nd interface, so when user clicked on this button, the watch will send the picked item's information to the pair iPhone through WatchConnectivity.
The problem is how can this button-click event on the 2nd interface trigger the WCSession action on the 1st main interface?
Thank you!
Paul
The proper way is to create delegate method in the class you manages WCSession and you would be able to interact using WatchConnectivity at any part of your watchOS app. Do not bound the code that manages WCSession with any interface.
I am developing an app for the Apple Watch and I would like to use the action demonstrated at the launch event where the user pushes into the screen (rather than a tap). Do you know what this is called and how I can access this?
You can only show a menu on that action. You use addMenuItem methods on WKInterfaceController.
The gesture you are referring to is called a Force Touch.
It is possible to use Force Touch as an input method in third party apps. You cannot register to receive notifications of Force Touch events however; there is nothing equivalent to a UIGestureRecogniser in WatchKit at present.
When you have a contextual menu in the current screen of your WatchKit app, it will automatically be activated by the OS when the user initiates a force touch. You can simulate this in the Apple Watch simulator by a click and hold with the mouse... the resulting animation will make it clear when a Force Touch even has been initiated, even on screens that do not have a contextual menu enabled.
To utilise this via Interface Builder, you simply:
Drag a menu into the relevant Watch App scene in interface builder.
Add between one and four menu items to the menu by dragging those into the menu.
Set names and images for those menu items.
Wire those menu items to IBActions in your WatchKit Extension.
Alternatively, you can set and clear menu items programatically from your WatchKit Extension, as outlined in the WatchKit API documentation. There are four relevant WKInterfaceController methods. In Swift:
func addMenuItemWithItemIcon(_ itemIcon: WKMenuItemIcon,
title title: String,
action action: Selector)
func addMenuItemWithImageNamed(_ imageName: String,
title title: String,
action action: Selector)
func addMenuItemWithImage(_ image: UIImage,
title title: String,
action action: Selector)
func clearAllMenuItems()
In Objective-C:
- (void)addMenuItemWithItemIcon:(WKMenuItemIcon)itemIcon
title:(NSString *)title
action:(SEL)action
- (void)addMenuItemWithImageNamed:(NSString *)imageName
title:(NSString *)title
action:(SEL)action
- (void)addMenuItemWithImage:(UIImage *)image
title:(NSString *)title
action:(SEL)action
- (void)clearAllMenuItems
Full information is in the API documentation for Configuring the Contextual Menu in WatchKit.
The first time you do create one of these menus, particularly if you do it in Interface Builder, it may well feel like you must have missed a step, since you did not have to connect the menu to something equivalent to a force touch gesture recogniser, but when you try it, you'll just find it works. It may well be that this will continue to be the only access third party developers have to force touch, even after we have the ability to make native apps for the Watch later in 2015.
it is called a contextual menu. you can do that using addMenuItem or in storyboards you add a menu which comes with an item, and then add additional items.
On the iPad I get weird situations with enabling and disabling the back/forward buttons. When web view starts and finishes the load, I check to enable/disable them based on canGoBack and canGoForward. But most of the time the buttons are enabled when they shouldn't be and disabled when they shouldn't be. Like on google, if I type something, no delegates are called so the buttons are disabled. In Safari their back/forward button changes. And if I go to a page on google, then back twice I'm on the first page again and my back button is still on. Is there a way to know when going back a page finished loading (seems like it doesn't call the delegate on back?) or know when canGoBack and canGoForward change YES/NO?
The delegate methods – webViewDidStartLoad: and – webViewDidFinishLoad: are not called sometimes, like on a google search. but i found out that – webView:shouldStartLoadWithRequest:navigationType: is called, so i can change the buttons and page title from that method now.
Hi need a little help, i have a window which is set to always show in the top right corner but it is not set to always key. The window has a few buttons on it and when a button is clicked the window becomes key, but what i want it to do is when a button is clicked i want the window to remove itself from being key.
So ideally the window becomes key when a button is clicked and in the method which the button calls i want to write a statement which will then perform the action of the button and remove the window from key.
However the window is declared under the app delegate and the method linked to the button is declared in a separate header file.
Anyone have any ideas how i can do this, any help would be much appreciated.
Thanks in advance, Sami.
There are a few solutions depending on the architecture of your application.
Send [[NSApp mainWindow] makeKeyWindow], which will make the main window become key.
Your application delegate could have a reference to the main window. In the action method that handles the button click, you could ask the application delegate to make the main window become key. The application delegate would send [mainWindow makeKeyWindow].
Your application delegate could have a reference to the window controller that manages the main window. In the action method that handles the button click, you could ask the application delegate to make the main window become key. The application delegate would ask the main window controller to do that, and the main window controller would send [[self window] makeKeyWindow].
Your application delegate could listen to the NSWindowDidResignKeyNotification notification and keep a reference to the last window that resigned being key. In the action method that handles the button click, you could ask the application delegate to return key status to that previous window. The application delegate would need to ignore NSWindowDidResignKeyNotification notifications when the window is your auxiliary window. This solution is better when there’s no single main window.
If the first solution is not applicable, a) your application delegate could conform to a protocol that declares a method responsible for restoring key status to the proper window, or b) your action method could post a notification informing the application that your action method has completed, and have the application delegate listen to that notification and restore key status to the proper window.
Note that even though I’ve suggested that the application delegate would implement the behaviour of restoring key status, other objects could be responsible for that. This is particularly easier when notifications are used since there’s no need to grab a reference to the object that will restore key status due to the inherent loose coupling provided by notifications.
I would like to enable the grayed out open file menu item within a non-document-based application. Document-based applications automatically give you a nice open file dialog with file extension filters based on plist entries etc... Surely, a simple elegant method exist to re-enable this functionality.
I have...
Added document types to the project properties window
Assigned my controller class as the application delegate
Added the delegate application:openFile: to my controller class
First, make sure your File->Open menu item's selector is connected to the openDocument: action of the First Responder.
Second, make sure you are responding to the action. Take a look at the Responder chain of a non-document application with an NSWindowController object. Any object within your responder chain can respond to the message, but it is best to pick the object which is the most capable and appropriate. Once you have decided which class in your responder chain is the most appropriate to handle the message, add the openDocument: action to it's implementation and write your code to respond to it accordingly.
The key is that something along the menu item's responder chain has to respond to the -openDocument: action. Normally it's the NSDocumentController. I'd take a look at how an empty document-based application sets up that menu item.