iOS dev - referencing js files from settings root.plist - cocoa-touch

Inside my webviewcontroller.m file I reference external JS and CSS files to be used to manipulate the content I pull into the WebViewUI.
I can reference external files using;
[webView stringByEvaluatingJavaScriptFromString: #"var script = document.createElement('script');"
"script.type = 'text/javascript';"
"script.src = 'http://xxx/xxx.js';"
"document.getElementsByTagName('head')[0].appendChild(script);"];
But I keep having problems with referencing file paths using the settings root.plist;
NSString *JSStr = #"var script = document.createElement('script');"
"script.type = 'text/javascript';";
JSStr = [JSStr stringByAppendingString:[defaults stringForKey:#"overridejspath" ]];
JSStr = [ JSStr stringByAppendingString:#"document.getElementsByTagName('head')[0].appendChild(script);"];
[webView stringByEvaluatingJavaScriptFromString:JSStr];
I can successfully reference CSS files using a similar method, but not JS files. Can you help?

Related

Evernote and SBApplication bridge - createNoteWithENML issue - resources added twice

The problem:
//Create Evernote App SBApplication
EvernoteApplication *evernoteApp = [SBApplication applicationWithBundleIdentifier:#"com.evernote.Evernote"];
evernoteApp.delegate = self;
//Take this ENML Code
NSString *enml = #"<div>This is an encrypted text for OneNote Saferoom.</div><div><br/></div><div>PDF file</div><div><en-media type=\"application/pdf\" style=\"cursor:pointer;\" height=\"43\" hash=\"fa7d7e650b2cec68f302b31ba28235d8\"/></div><div><br/></div><div>Image</div><div><en-media style=\"height: auto;\" type=\"image/png\" hash=\"64957a2bd851f625383a5b9e410965d7\"/></div>";
//Create correct Array of URLS for above (Set the URLs before)
NSArray *resourceURLs = [NSArray arrayWithObjects:url2,url1,nil];
//Upload the note to Evernote
[evernoteApp createNoteFromFile:nil fromUrl:nil withText:nil withHtml:nil withEnml:[NSString stringWithFormat:#"<en-note>%#</en-note>",enml] title:noteTitle notebook:workingNotebook tags:tags attachments:resourceURLs created:nil];
And now I get the note with additional duplicated resources (Evernote app just adds all resources from resourceURLs array to the end of the note):
Tried the following
remove resourceURLs array - no resources added
using HTML and adding resource URLs - structure is not kept, resources appear at the end only
converting from ENML to HTML using Inline resources function (ENMLUtility) - resources are not displayed
I am starting to believe that there is a bug in how Evernote.app handles createNote request.
Resources to test
PDF sample file for above resource:
https://www.dropbox.com/s/t8pgzzexms0nl7w/dec-pdf-sample.pdf?dl=0
Image sample
https://www.dropbox.com/s/nagaei1hng6ziwc/dec-touchID_blue_80%403x.png?dl=0
Generated Evernote.h file for bridging:
https://www.dropbox.com/s/7u1zdb8c71ydwag/Evernote.h?dl=0
Any help will be appreciated.
Update 1:
Tested with pure AppleScript, still resources are duplicated:
https://www.dropbox.com/s/rvpc4est8ef7q4c/EvernoteAppleScript_bug.scpt?dl=0
Thanks,
Ilia

Objc scriptingbridge how open new Finder window in a specific folder

I want to open a new Finder window of a specific size in a specific position and displaying a specific folder.
In ScriptingBridge (XCode 6, Mavericks 9.4) I can open a new Finder window and have figured out how to read the URL of the folder it opens. But I am really struggling with how to set the folder to something different.
I have tried to assign the window a 'target' SBObject initialised with a 'URL' property.
but the URL property is readonly although 'target' seems not to be. I've used 'get' to ensure there is a FinderFolder object and a FinderFinderWindow object.
I've tried using a dictionary of properties with a URL key and creating a 'folder'.
FinderFolder *folder = [[[_finder classForScriptingClass:#"folder"] alloc]
initWithProperties:dict];
[[_finder folders] addObject:folder];
I have read the Apple docs and looked for examples all over but cannot find an instance of someone assigning the folder path.
// open folder "Documents" of home folder
FinderFolder *theHomeFolder = [theFinder home];
NSLog(#"theHomeFolder: %#",theHomeFolder);
SBElementArray * theHomeFolderFolders = [theHomeFolder folders];
NSLog(#"theHomeFolderFolders: %#",theHomeFolderFolders);
FinderFolder *theDocsFolder = [theHomeFolderFolders objectWithName:#"Documents"];
NSLog(#"theDocsFolder: %#",theDocsFolder);
[theDocsFolder openUsing:nil withProperties:nil];
FinderFinderWindow * docsFolderWindow = (FinderFinderWindow*) [theDocsFolder containerWindow];
NSLog(#"docsFolderWindow: %#",docsFolderWindow);
docsFolderWindow = [docsFolderWindow get];
NSLog(#"docsFolderWindow: %#",docsFolderWindow);
// change its bounds
docsFolderWindow.bounds = NSMakeRect(64., 64., 800, 600.);
// other fun stuff…
[docsFolderWindow setCurrentView:FinderEcvwListView];
[[docsFolderWindow iconViewOptions] setArrangement:FinderEarrArrangedByName];
[docsFolderWindow cleanUpBy:#selector(name)];
docsFolderWindow.toolbarVisible = NO;
docsFolderWindow.statusbarVisible = NO;
docsFolderWindow.sidebarWidth = 0;
There are a few different ways. The other answer works, or you could explicitly make a new Finder window and set its target property:
NSURL *u = [NSURL fileURLWithPath:#"/tmp"];
FinderFinderWindow *w = [[[theFinder classForScriptingClass:#"Finder window] alloc] init];
[[theFinder finderWindows] addObject:w];
[w setTarget:u];
You could also set it to an SBObject referring to a Finder item, such as theDocsFolder from the other answer.

Too Many Directories when opening a CocosBuilder project

When I open a cocosbuilder project again after I adding some new directories, it pops up a dialog that says
Too Many Directories
You have created or opened a project which is in a directory with very many sub directories. Please save your project-files in a directory together with the resources you use in your project.
I know it is because there are too many directories.
But I wonder if there is any other method that can solves this problem except removing my new added directories.
Thanks.
You could always remove the warning directly in CocosBuilder source and rebuilt it, provided that you use the github version.
Otherwise you could petition for the change requested by MK on github.
The offending code is located in CocosBuilderAppDelegate.m, around line ~1155
[[CocosBuilderAppDelegate appDelegate] modalDialogTitle:#"Too Many [...]
You will have to remove this line in at least two places.
- (void) checkForTooManyDirectoriesInCurrentDoc
{
if (!currentDocument) return;
if ([ResourceManager sharedManager].tooManyDirectoriesAdded)
{
// Close document if it has too many sub directories
NSTabViewItem* item = [self tabViewItemFromDoc:currentDocument];
[tabView removeTabViewItem:item];
[ResourceManager sharedManager].tooManyDirectoriesAdded = NO;
// Notify the user
[[CocosBuilderAppDelegate appDelegate] modalDialogTitle:#"Too Many Directories" message:#"You have created or opened a file which is in a directory with very many sub directories. Please save your ccb-files in a directory together with the resources you use in your project."];
}
}
- (BOOL) checkForTooManyDirectoriesInCurrentProject
{
if (!projectSettings) return NO;
if ([ResourceManager sharedManager].tooManyDirectoriesAdded)
{
[self closeProject];
[ResourceManager sharedManager].tooManyDirectoriesAdded = NO;
// Notify the user
[[CocosBuilderAppDelegate appDelegate] modalDialogTitle:#"Too Many Directories" message:#"You have created or opened a project which is in a directory with very many sub directories. Please save your project-files in a directory together with the resources you use in your project."];
return NO;
}
return YES;
}
Update:
In CocosBuilder/ccBuilder/ResourceManager.h
There is a marco defined as below:
#define kCCBMaxTrackedDirectories 50
So we can simply change 50 to a larger number, and the problem can be solved.

Load local HTML into WebView

Can I load a local HTML file (with images and ...) into a WebView?
Just setting the Source parameter does not do the trick.
You can load it from a file as long as the file is part of the app package, e.g.:
WebView2.Source = new Uri("ms-appx-web:///assets/text.html");
From WebView.Navigate
WebView can load content from the application’s package using
ms-appx-web://, from the network using http/https, or from a string
using NavigateToString. It cannot load content from the application’s
data storage. To access the intranet, the corresponding capability
must be turned on in the application manifest.
For a 'random' file, I suppose you could prompt user via file picker to select the file then read it into a string and use NavigateToString, but the user experience there may be a bit odd depending on what you're trying to accomplish.
I was working at this problem for a long time and I found a way to do that:
At first you should save it in InstalledLocation folder. If you haven't option to create a new .html file you can just use file.CopyAsync(htmlFolder, fname + ".html");
Look into my example:
StorageFolder htmlFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.CreateFolderAsync(#"HtmlFiles", CreationCollisionOption.GenerateUniqueName);
IStorageFile file = await htmlFolder .CreateFileAsync(fname + ".html", CreationCollisionOption.GenerateUniqueName);
and than you can easily open your .html file:
var fop = new FileOpenPicker();
fop.FileTypeFilter.Add(".html");
var file = await fop.PickSingleFileAsync();
if (file != null)
{
string myPath = file.Path.Substring(file.Path.IndexOf("HtmlFiles"));
myWebview.Navigate(new Uri("ms-appx-web:///" + myPath));
}
Remember just only from InstalledLocation you can open it with ms-appx-web:///

Localizable.strings error - compiler says file is missing

I tried adding a Localizable.strings file and add some strings to test with, everything works fine.
However, when I try to add a localization things starts to get weird. I am able to add a localization (english and russian) and I can see in finder that the files are listed in the two folders; ru.lproj and en.lproj.
When I clean and build I get the following compilation error:
Copy .strings file Error
The file "Localizable.strings" couldn't be opened because there is no such file.
Fixed it by a push in the right direction from this link provided by tiguero in the comment.
I looked further into the .pbxproj file and found this funky row, that looked fishy:
6AAE55EC1551A42500C1F3F0 /* Localizable.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = "<group>"; };
I removed it, cleaned and rebuild. It is now replaced by the following line:
6AC473DC1624BF3E00503305 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6AC473DE1624BF3E00503305 /* Localizable.strings */; };
And it works!