Expected ";" before "WebView" in Xcode - xcode

I am trying to follow the basic WebKit tutorial provided on Apple's Mac Dev site:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DisplayWebContent/DisplayWebContent.html
I am at the part where I update my title to the current page's title and update the URL to the current URL. However, when I try to Build this:
- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame //2 errors on this line stating: expected ")" before "WebView" and expected ")" before "WebFrame"
{
//Only report feedback from main frame.
if (frame == [sender mainFrame]) {
NSString *url = [[[[frame provisionalDataSource] request] URL] absoluteString];
[textField setStringValue:url];
}
}
- (void)webView:(WebView *)sender didRecieveTitle:(NSString *)title forFrame:(WebFrame *)frame // Same 2 errors as the first line of code
{
if (frame == [sender mainFrame]){
[[sender window] setTitle:title];
}
}
Could somebody please tell me what is wrong with this? It is the exact code as Apple's example.
--Thank you

Did your right click on "frameworks" and click "Add existing Framework" and add Webkit.framework?
Did you include the include files?

Related

PhotoEditorSDK configuration

I am trying to configure the photoeditorSDK for iOS, but am struggling.
My current issues are the following:
1. When a user clicks on the brush toolMenuItem, it does not do anything. Other toolMenuItems do what they are supposed to (e.g. Size).
Similarly, when a user adds text through the Text Menu Item, it works, however when they try to resize the text - they can't click it.
I believe these issues are related - that is why I opted them together.
Here's the code snippet used to configure the control:
NSError *dataCreationError;
NSURL *aLocalURL = [NSURL URLWithString:filepath];
NSData *imageData = [NSData dataWithContentsOfFile:aLocalURL.path options:0 error:&dataCreationError];
if (imageData && !dataCreationError) {
PESDKConfiguration *configuration = [[PESDKConfiguration alloc] initWithBuilder:^(PESDKConfigurationBuilder * _Nonnull builder) {
// See Configuration section
}];
NSMutableArray<PESDKPhotoEditMenuItem *> *menuItems = [[PESDKPhotoEditMenuItem defaultItems] mutableCopy];
[menuItems removeLastObject]; // Remove last menu item ('Magic')
PESDKPhotoEditViewController *photoEditViewController = [[PESDKPhotoEditViewController alloc] initWithData:imageData configuration:configuration];
photoEditViewController.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:photoEditViewController];
dispatch_async(dispatch_get_main_queue(), ^{
[self.viewController presentViewController:navigationController animated:YES completion:nil];
});
} else if (dataCreationError) {
NSLog(#"Failed to open given path: %#", dataCreationError);
}
This is a bug on our side and will be fixed with the next release, which will go live this week. As a workaround, we updated your subscription. You just need to generate a new license file using our dashboard and replace the existing one in your app. This should fix both issues, but will add the Sticker tool to your menu items. You may remove it just like you did with the Magic tool.
If you have further questions, just let me know!

Gluon Mobile Share Button Implementation

Does Gluon Mobile have any guidance on implementing a share button? My goal is to be able to share a string containing a link to different apps on the phone. At the moment, I need this only for the iOS implementation. I was able to find this link that provides a simple way to do this in Objective-C:
- (IBAction)shareButton:(UIBarButtonItem *)sender
{
NSString *textToShare = #"Look at this awesome website for aspiring iOS Developers!";
NSURL *myWebsite = [NSURL URLWithString:#"http://www.codingexplorer.com/"];
NSArray *objectsToShare = #[textToShare, myWebsite];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
NSArray *excludeActivities = #[UIActivityTypeAirDrop,
UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo];
activityVC.excludedActivityTypes = excludeActivities;
[self presentViewController:activityVC animated:YES completion:nil];
}
Looking at the GoNative application example on the Gluon website, it seems like I can use the above code snippet where needed as the native iOS code. Do I have to update the ios build gradle to account for the UIActivity class mentioned in the first link above?
Update*
I have been able to get this to work based on help in this question here.
However when trying to install the native library, I get this error which is understandable as self is unknown in the scope of the code. How would I be able to do this? Instantiate a popover or dialog and pass the activityVC to it?
/Users/ashishsharma/NetBeansProjects/konfamdbranch/src/ios/n‌​ative/Share.m:25:6: error: use of undeclared identifier 'self' [self presentViewController:activityVC animated:YES completion:nil];
So I was able to solve this using examples on the internet (shown above) along with going through the existing code for the Barcode Scan Service. The issue I was experiencing with the above code was that the present view controller could not be found. However, looking at the bit bucket source for Barcode Scan, I was able to get the root view with the following code:
if(![[UIApplication sharedApplication] keyWindow])
{
NSLog(#"key window was nil");
return;
}
// get the root view controller
UIViewController *rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];
if(!rootViewController)
{
NSLog(#"rootViewController was nil");
return;
}
Then in the code snippet I placed in the question, replace self with rootViewController:
[rootViewController presentViewController:activityVC animated:YES completion:nil];
This leads to the modified code snippet:
#import <UIKit/UIKit.h>
#include "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/jni.h"
JNIEXPORT void JNICALL Java_com_gluonhq_charm_down_plugins_ios_IOSShareService_shareMessage
(JNIEnv *env, jclass jClass, jstring jMessage) {
if(![[UIApplication sharedApplication] keyWindow])
{
NSLog(#"key window was nil");
return;
}
// get the root view controller
UIViewController *rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];
if(!rootViewController)
{
NSLog(#"rootViewController was nil");
return;
}
NSString *textToShare = #"Check out this site!";
NSURL *myWebsite = [NSURL URLWithString:#"http://www.google.com/"];
NSArray *objectsToShare = #[textToShare, myWebsite];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
NSArray *excludeActivities = #[UIActivityTypeAirDrop,
UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo];
activityVC.excludedActivityTypes = excludeActivities;
[rootViewController presentViewController:activityVC animated:YES completion:nil];
}
Note I followed the GoNative application to generate my objective-c/ios files correctly.
This leads to a minimal functionality share implementation only because I don't have Facebook installed on the IPhone simulator.

Cocoa webview textfield not accepting keystrokes

I am a newbie in OSx development.
I have a Cocoa application which uses a Webview. Everything is working fine, except for the textfield in the webview. I know how to enable keystrokes in NSTextField, but not the ones in the Webview. I've been searching the web all day, but with no luck.
I badly need some help on how to enable the keystrokes to implement keyboard shortcut keys.
Example:
copy -> command + c
paste -> command + v
cut -> command + x
Any help would be very much appreciated.
I got the answer now. I've realized that I forgot to implement
- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
to the class which handles the Webview.
#Kimpoy, thanks for the reference to performKeyEquivalent!
For completeness, I implemented it this way...
Subclass your webview from WebView and implement the method:
- (BOOL)performKeyEquivalent:(NSEvent *)theEvent {
NSString * chars = [theEvent characters];
BOOL status = NO;
if ([theEvent modifierFlags] & NSCommandKeyMask){
if ([chars isEqualTo:#"a"]){
[self selectAll:nil];
status = YES;
}
if ([chars isEqualTo:#"c"]){
[self copy:nil];
status = YES;
}
if ([chars isEqualTo:#"v"]){
[self paste:nil];
status = YES;
}
if ([chars isEqualTo:#"x"]){
[self cut:nil];
status = YES;
}
}
if (status)
return YES;
return [super performKeyEquivalent:theEvent];
}
Credit to #aventurella over here: https://github.com/Beats-Music/mac-miniplayer/issues/3. Just modified slightly to return the super response as default because it should propagate down to its subviews.
As a note, I'd recommend implementing a log or similar in your custom webview to make sure you really are working with your class:
- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
// Drawing code here.
NSLog(#"Custom webview running...");
}

Xcode Open target=_blank links in Safari

I'm pretty new to Xcode... I have a single page iOS app that just has a UIWebView opening a specific URL. I would like any links within the pages that have target="_blank" to open in Safari, rather than inside the app.
Can someone tell me how to accomplish this? (I've searched everywhere) and also tell me in which files and where to put the code? Thank you SOOO much!!
EDIT
I implemented the following code in my ViewController.m file:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Add line below so that external links & PDFs will open in Safari.app
webView.delegate = self;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.example.com/"]]];
}
// Add section below so that external links & PDFs will open in Safari.app
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
[[UIApplication sharedApplication] openURL:request.URL];
return false;
}
return true;
}
But for the line webView.delegate = self; I am getting a yellow warning that says:
Assigning to 'id'from incompatible type 'UIWebViewViewController *const_strong'
What is this error, and how can I fix it in Xcode?
Perhaps following answer on SO can solve your problem or atleast give you some ideas on how to achieve what you are trying to do:
UIWebView open links in Safari
This is the way we solved it:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
first.delegate = (id)self;
[first loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.website.com"]]];
}
// Add section below so that external links & PDFs will open in Safari.app
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeOther) {
NSString *checkURL = #"http://www.linkyouwanttogotoviasafari.com";
NSString *reqURL = request.URL.absoluteString;
if ([reqURL isEqualToString:checkURL])
{
[[UIApplication sharedApplication] openURL:request.URL];
return false;
}
else {
return true;
}
}
return true;
}

Drag and Drop with NSStatusItem

I'm trying to write an application that allows the user to drag files from the Finder and drop them onto an NSStatusItem. So far, I've created a custom view that implements the drag and drop interface. When I add this view as a subview of an NSWindow it all works correctly -- the mouse cursor gives appropriate feedback, and when dropped my code gets executed.
However, when I use the same view as an NSStatusItem's view it doesn't behave correctly. The mouse cursor gives appropriate feedback indicating that the file can be dropped, but when I drop the file my drop code never gets executed.
Is there something special I need to do to enable drag and drop with an NSStatusItem?
I finally got around to testing this and it works perfectly, so there's definitely something wrong with your code.
Here's a custom view that allows dragging:
#implementation DragStatusView
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
//register for drags
[self registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
//the status item will just be a yellow rectangle
[[NSColor yellowColor] set];
NSRectFill([self bounds]);
}
//we want to copy the files
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender
{
return NSDragOperationCopy;
}
//perform the drag and log the files that are dropped
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *pboard;
NSDragOperation sourceDragMask;
sourceDragMask = [sender draggingSourceOperationMask];
pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
NSLog(#"Files: %#",files);
}
return YES;
}
#end
Here's how you'd create the status item:
NSStatusItem* item = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
DragStatusView* dragView = [[DragStatusView alloc] initWithFrame:NSMakeRect(0, 0, 24, 24)];
[item setView:dragView];
[dragView release];
Since Yosemite, the method for setting a view on NSStatusItem is deprecated but fortunately there is a much nicer way using the new NSStatusItemButton property on NSStatusItem:
- (void)applicationDidFinishLaunching: (NSNotification *)notification {
NSImage *icon = [NSImage imageNamed:#"iconName"];
//This is the only way to be compatible to all ~30 menu styles (e.g. dark mode) available in Yosemite
[normalImage setTemplate:YES];
statusItem.button.image = normalImage;
// register with an array of types you'd like to accept
[statusItem.button.window registerForDraggedTypes:#[NSFilenamesPboardType]];
statusItem.button.window.delegate = self;
}
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
return NSDragOperationCopy;
}
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
//drag handling logic
}
Please be aware that the button property is only available starting in 10.10 and you might have to keep your old solution if you support 10.9 Mavericks or below.

Resources