How to debug the main SafariPlugIn project? - cocoa

Ok, Now I want to add a menu in the safari menubar. I Create a Cocoa bundle project in Xcode .and then change the target extension is "webplugin" .and then add WebPluginMIMETypesFilename
com.example.webplugin.plist
to the info.plist.but I don't know the is right?. I make the prinpical class is my main plugin class SafariPlug . and then In the safariPlug.m I implement the methods:
// This method returns an NSView object that conforms to the WebPlugIn informal protocol.
(NSView *)plugInViewWithArguments:(NSDictionary *)arguments
{
return [[[self alloc] initWithArguments:arguments] autorelease];
}
(id)initWithArguments:(NSDictionary *)arguments
{
self = [super init];
if (self)
[MenuController sharedController]; // trigger the menu items to be added
return self;
}
at the end I followed the url:run safari to debug plunIn project
add a debug bundle:myProject.webplugin into the folder:/library/internet plug-ins/
But when I make a breakpoint into the
(NSView *)plugInViewWithArguments:(NSDictionary *)arguments
the program didn't load in the debug mode? SomeOne which have experience can tell me the step of add a menu into the safari? Thank you very much!

Safari will not load your plugin unless you load a webpage that references your plugin. So I'm afraid the plugin type you're working on is not officially supported, by the current plugin API of safari.
You can use SIBML to write this kind of plugin. But SIMBL is not something officially supported by Apple, and a lot of people consider it a hack.

Related

Next step to Make Binding for embedded framework for Xamarin.iOS?

I'm trying to use Native iOS framework from BLE chip bender(nordic) on Xamarin iOS.
this framework (iOS Native - swift) : https://github.com/NordicSemiconductor/IOS-DFU-Library/tree/master/documentation
I made a fat framework with those iOS library. And I looked this doc.
https://developer.xamarin.com/guides/ios/advanced_topics/embedded_frameworks/
I imported it as Native framework on Xamarin.iOS project. And I want to use it.
Below code is from that I used when i'm making iOS native app. I will have to use it on Xamarin.
(part of my app's code(objc base) - using that library )
DFUServiceInitiator *initiator = [[DFUServiceInitiator alloc] initWithCentralManager: [DeviceManager getInstance].central target:[DeviceManager getInstance].connectedPeripheral];
[initiator withFirmwareFile:nil];
initiator.forceDfu = [[[NSUserDefaults standardUserDefaults] valueForKey:#"dfu_force_dfu"] boolValue];
initiator.packetReceiptNotificationParameter = [[[NSUserDefaults standardUserDefaults] valueForKey:#"dfu_number_of_packets"] intValue];
initiator.logger = self;
initiator.delegate = self;
initiator.progressDelegate = self;
// initiator.peripheralSelector = ... // the default selector is used
DFUServiceController *controller = [initiator start];
So in Xamarin.iOS project.
I will use framework that I just imported. And I tried declaring 'DFUServiceInitiator' class. But nothing works but gives 'could not be found' error. Maybe there is many things left I have to do. Yes, this can't be that easy.
Next step is 'binding(wrapping) framework to c#'? Could you guide little bit please?
Is this document I should look next?
https://developer.xamarin.com/guides/ios/advanced_topics/native_interop/
or this?
https://developer.xamarin.com/guides/ios/advanced_topics/binding_objective-c/walkthrough/
Thanks.
You can not simply include a Objective-C or Swift library in you Xamarin project and use it by copying Objective-C or Swif code. You need to create a binding project to create wrapping-classes to get a .NET-api. And that is where Xamarin binding projects come into play.
So you should go with https://developer.xamarin.com/guides/ios/advanced_topics/binding_objective-c/walkthrough/ and learn about how to build bindings for native libraries. Depending on the library it isn't that hard.

Xcode Autocomplete Member From Class Extension

Autocomplete isn't working for me when accessing members from a class extension in Xcode (6.3.2).
I made a UIColor extension, and I am accessing them via UIColor().sampleExtendedColorName(), and it does not show up while I'm typing. Autocomplete works for everything other than this. Is there a setting I can change?
extension UIColor{
func sampleExtendedColorName() -> UIColor {
return UIColor(red:200/255, green:100/255, blue:120/255, alpha:1.0)
}
}
Update (new info):
So autocomplete is working if I access the UIColors from a ViewController that directly subclasses UIViewController, but if I subclass a custom CustomViewController that is a subclass of UIViewController, autocomplete doesn't show up for some reason.
Checking all the Target Memberships is working fine. If you don't know where the Target Membership is,
Go to your swift file (Eg: ViewController.swift)
On the right side in the Utilities panel, Click file inspector
You can see Target Membership there.
Check all the fields.
Figured it out, issue was on my ColorExtension.Swift file in my Xcode project. I needed to check all the Target Memberships.

Unable to test the Live rendering in Xcode 6

Recently I have downloaded the new XCode 6 beta version.In the apple docs it is saying that we can see the output while editing the Code in .swift file without build and run. I haven't find any ways to fulfill the live rendering. Could you please help me out on this? Thanks in advance
It's important that you set up your project as a cocoa touch framework!
Then:
1.) Add #IBDesignable to your custom UIView before the class definition. (It might be helpful to override the drawInRect function for the beginning.)
2.) Add a UIView object to your .xib or .storyboard file at it change its class to your customView with the #IBDesignable attribute.
It should work.
Tipp: Check out this years WWDC video: "What's New to Interface Builder in Xcode 6" - There is explained how to set it up.
You actually do not have to create Cocoa Touch framework. If you create a custom view with nib that contains UI elements and show them another view just add the code below to your custom view
-(instancetype)initWithFrame:(CGRect)frame{
#if !TARGET_INTERFACE_BUILDER
self= [super initWithFrame:frame];
if(self){
}
return self;
#else
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
return [bundle loadNibNamed:NSStringFromClass([self class]) owner:self options:nil][0];
#endif
}
Since you don't have your main bundle while you are on design mode, you won't be able to retrieve your custom view to render. In addition to this, if you have extra properties and set them onto your ui elements, you may do this within method
-(void)prepareForInterfaceBuilder{
}
This is my solution Custom View
Custom View
Live Render (Objc)
Live Render (Swift)
Another solution How to make awesome UI components in iOS 8 using Swift and XCode 6.
(Swift, didset,live render)

Is Default Xcode 4.6.3 New Project With Cocoa Application Template Structure Recommended?

I am using Xcode 4.6.3, and I have created a new project using the “Cocoa Application” template. The default structure seems a bit funny to me, and I was wondering if it is the recommended structure.
Specifically, three of the files created by the template are:
MainMenu.xib
AppDelegate.h
AppDelegate.m
The MainMenu.xib file contains the main menu definition, and the definition of the main window. It seems strange to me to have the main window defined in a file called MainMenu.xib. Is this the recommended place to define the main window?
I was expecting to see a files like MainWindow.h, and MainWindow.m subclassed from NSViewController. The current structure created from the template would lead me to create handlers for the main window events in the app delegate. This also seems strange to me. Is it recommend to put the main window outlets and handlers in the app delegate?
One of the first things I do is rip that window out.
I was expecting to see a files like MainWindow.h, and MainWindow.m subclassed from NSViewController.
View controllers are not windows, and windows are not view controllers.
What I do (after deleting the window from the MainMenu nib) is create a window controller subclass, using the Objective-C Class file template and enabling the “and a nib, too, please” option (which appears when the superclass is NSViewController or NSWindowController).
(Don't forget to select the nib afterward and click the button in the File Inspector to make it localizable, since Xcode doesn't do that by default for some reason.)
In the implementation of the subclass, I have something like the following:
#implementation MyWindowController
- (instancetype) init {
return [self initWithWindowNibName:NSStringFromClass([self class])];
}
//and all my app-specific stuff
#end
In the app delegate, I delete the outlet that once referred to the MainMenu-born window, and then I create the window controller:
#implementation MyAppDelegate
{
MyWindowController *_wc;
}
- (void) applicationWillFinishLaunching:(NSNotification *)notification {
_wc = [MyWindowController new];
[_wc showWindow:nil];
}
- (void) applicationWillTerminate:(NSNotification *)notification {
[_wc close];
_wc = nil;
}
#end
(I use ARC; if you don't, you'll want to add a release message in there.)
Is it recommend to put the main window outlets and handlers in the app delegate?
No. That is outside the scope of what the application's delegate should do.
For an extremely simple one-window app, you might want to make the window controller the application's delegate. But even that is different from making an app delegate that isn't a window controller handle actions, be a data source, etc. It's the difference between adding a little bit of responsibility to a window controller, and adding a whole lot of responsibility to an app delegate.
I keep them separate at all times. It's a bit of extra work in the simple cases, but my project is cleaner, which makes me happier, and I usually need to do it sooner or later anyway.

Is there a syntax highlighting editor component for Mac OS X

I am looking for a syntax highlighting component that I can include in a Mac OS X XCode project to allow editing of Ruby, C++, Lua, etc.
I need a component that is open source or has the source included.
My Google searches didn't turn up much in the way of Mac OS X frameworks or components at all, let alone the type I am looking for.
Thanks for any pointers!
UKSyntaxColoredTextDocument (Mac-specific) or Scintilla (cross-platform and in use in a variety of editors, including Komodo) might be what you're looking for.
Try to use scintilla. http://www.scintilla.org/
You could try using CodeMirror. I do this in my SQLite Professional app to highlight user editable queries. It's also fairly simple to setup:
In your project, add the CodeMirror contents as a Folder rather than a group.
Add the WebKit.Framework to your project.
Add a WebView to your nib/xib.
Add the following code:
// Load our webview from our local CodeMirror path
NSURL * url = [NSURL fileURLWithPath: [NSString stringWithFormat:#"%#/CodeMirror/Demo/preview.html", [[NSBundle mainBundle] resourcePath]]];
NSString * html = [NSString stringWithContentsOfURL: url encoding:NSUTF8StringEncoding error:nil];
[webView.mainFrame loadHTMLString: html baseURL: url];
They also have lots of formats pre-defined, so it works quite well. The one issue I have found with this, is that the native Find dialog does not work when in the context of the WebView.

Resources