CPOpenPanel not working in Cappuccino - cappuccino

I am trying to use CPOpenPanel to select a file for upload,
when I call runModal upon CPOpenPanel object , it is throwing an exception as
CPInvalidArgumentException: - [CPOpenPanel runModel] unrecognized selector sent to instance 0x005585
Does CPOpenPanel still has bugs in cappuccino framework ?
Am I missing something ? I just created an object and calling runModal on that object.

CPOpenPanel only works in our NativeHost environment, not the the browser. The same for CPSavePanel. Those are about the only classes this is true for.

The error show you that the runModel doesn't exist for CPopenPanel. it's not runModel but runModal, and If you want to upload a file look at
this thread https://groups.google.com/forum/m/?fromgroups#!topic/objectivej/6ZupNuR5DIw
It's about 2 libs for uploading file with a simple button or drag and drop upload.
Ben

This should work with NativeHost (jake run-desktop):
var panel = [[CPOpenPanel alloc] init];
[panel runModal];

Related

NSWorkspace throws error when launch the mail application

I tried the below code, it is working fine for me. Also am able to launch the mail application as well.
//Note the below path is coming from bundle identifier of Mail APP
NSString *path=#"/Applications/Mail.app"
NSURL *mailURL = [NSURL URLWithString:path];
NSError *err=nil;
[[NSWorkspace sharedWorkspace] launchApplicationAtURL:mailURL
options:NSWorkspaceLaunchDefault
configuration: someData
error:&err];
But it throws me the below error message on console, What it means actually. How to resolve the below issue.
CFURLCopyResourcePropertyForKey failed because it was passed this URL which has no scheme: /Applications/Mail.app
The error is thrown because you are not creating a valid URL. The URL needs a scheme, in your case it is file: so the correct URL is file:///Applications/Mail. You need to create a file URL which works as follows:
NSString *path=#"/Applications/Mail.app";
NSURL *mailURL = [NSURL fileURLWithPath:path];
Note that your code breaks if the user ha moved Mail.app to another location. Also note that if the user doesn't use Apple's Mail app, it won't work well for the user either.
One possibility of doing it a more correct way is given here: How to launch New Message window in Mail.app from my application
Another option is to get the URL for Mail.app in a more fleixble way covering for users that have moved Mail.app. The idea is to use the bundle identifier and then ask NSWorkspace to launch this application by using
- (BOOL)launchAppWithBundleIdentifier:(NSString *)bundleIdentifier
options:(NSWorkspaceLaunchOptions)options
additionalEventParamDescriptor:(NSAppleEventDescriptor *)descriptor
launchIdentifier:(NSNumber **)identifier
(see also in detail here http://theocacao.com/document.page/183).

iOS Extension kJavaScriptFinalizeArgumentKey

The iOS 8 Extension SDK allows you to interact with a web pages using JavaScript.
The guide references a kJavaScriptFinalizeArgumentKey constant to use as a dictionary key when passing data back to the finalize() method in the JS.
Xcode doesn't recognise this, nor the other kJavaScriptResultsKey referenced in the docs.
Does anyone know if this is either not yet implemented, or if I need to import a module for this to work?
replace 'kJavaScriptFinalizeArgumentKey' with 'NSExtensionJavaScriptFinalizeArgumentKey'
so the SDK sample should be
NSExtensionItem *extensionItem = [[NSExtensionItem alloc] init];
extensionItem.attachments = #[[[NSItemProvider alloc] initWithItem: #{NSExtensionJavaScriptFinalizeArgumentKey: #{#"bgColor":#"red"}} typeIdentifier:(NSString *)kUTTypePropertyList]];
[self.extensionContext completeRequestReturningItems:#[extensionItem] completionHandler:nil];

Get the URL from webview component

I am using the WebView component and sometimes I reload this component. But sometimes, before reloading I would like to get the URL where the WebView is still pointing.
Is it possible to get this information??
Thank you in advance.
Alex
UIWebView *myWebView = // ... well, we'll just say it exists.
NSLog(#"last loaded or currently loading URL: %#", myWebView.request.URL);
The request is a NSURLRequest object which was used to request the page so you can pretty much get anything might need out of it.

How to force NSArrayController to reload MOC contents to reflect latest fresh data

I am working on a Mac & iOS App, with iCloud CoreData in between to synchronize the data.
When I update some thing from iOS App, and the updates are already migrated to the PersistentStore in Mac App while the Mac App is running. The problem is I cannot find an effective way to force the NSArrayController to reload all data from the store.
tried -(void) fetch:(id)sender; only can see the delete or added entity, but the updated model property not refreshed...
Please help. Thanks
If you see the latest data in the managed object context, but not in the array controller, you want:
[_yourManagedObjectContext processPendingChanges];
[_yourArrayController fetchWithRequest:nil merge:YES error:&error];
[_yourArrayController rearrangeObjects];
I use this in a Mac/iOS iCloud app to update the Mac app's data when the iCloud store changes.
Following is the reply from Apple's Developer Technical support. It worked for me. Thanks all for providing solutions.
For the OS X app, when reloadFetchResults is called, you can ask the NSManagedObjectContext to reset itself and perform the fetch again.
- (void)reloadFetchedResults:(NSNotification *)note
{
NSDictionary *userInfoDict = [note userInfo];
NSManagedObjectContext *moc = self.coreDataController.mainThreadContext;
// this only works if you used NSMainQueueConcurrencyType
// otherwise use a dispatch_async back to the main thread yourself
//
[moc performBlock:^{
[self mergeiCloudChanges:userInfoDict forContext:moc];
[moc reset];
[self.tableArrayController fetch:self];
}];
}
I've found that
[self.managedObjectContext reset];
[myArrayController fetch:self];
forces my NSTableView (with NSArrayController) to re-populate and display newly processed NSManagedObjects.
in case someone else finds this...
in my case, I was building the array from user interaction (not Core Data), and then trying to show the tableView when they were done (on the same window)... and of course... seeing nothing!
[arrayController rearrangeObjects];
just before I wanted to show the tableView fixed it for me.

Opening a url on launch

What method must I implement in my cocoa application’s delegate so that on launch, it’ll open a url? (http/https, in this case) I’ve already implemented the url schemes, I just need to know how I can get my application to open on a url notification.
Update: I’m sorry, I wasn’t very clear. My application IS a browser that support https/http urls, but can only open them when it’s already running. What can I do to implement support for open urls in my app on launch?
When an application finishes launching on OS X, NSApp (the global NSApplication instance for the program) sends its delegate the applicationDidFinishLaunching: message (via the notification system). You can implement that method in your delegate to handle the notification and open a browser window in response, using NSWorkspace. Something like the following would work:
// Your NSApp delegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:#"http://www.example.com/"]];
}
It's not a delegate method. You need to implement an Apple Event handler for the getURL event.
As luck would have it, this is exactly the case Apple uses to demonstrate implementing an Apple Event handler.
I already had implemented the getURL event, so that alone isn’t enough to get the application to open a url on launch. The trick is that the AppleEvent must be installed in applicationWillFinishLaunching: not applicationDidFinishLaunching:. Otherwise, the event isn’t sent at all because the app hasn’t registered it in time.
To implement a protocol handler that you can select (in Safari preferences, for example) as the "default browser" and which will launch in response to HTTP / HTTPS, you need to do a few things.
Add .scriptSuite and .scriptTerminology files to your project resources. These will tell Mac OS X that you'll be handling the GetURL command.
Add a CFBundleURLTypes key to your Info.plist file listing the "URL Schemes" that your app will handle.
Also in Info.plist, add the NSAppleScriptEnabled key with the value YES.
Add a new class to your application as a subclass of NSScriptCommand and implement the -(id)performDefaultImplementation selector. From within this function you will find the clicked URL in [self directParameter]. Pass this on to your app's URL handler!
For the full details check out the article:
http://www.xmldatabases.org/WK/blog/1154_Handling_URL_schemes_in_Cocoa.item

Resources