This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-10-10 09:09:33

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Objective-C: Converting Scratch projects to Mac apps (HELP!)

OK, I was trying to convert a normal Scratch project to a standalone Mac (not iOS!) app. I tried to embed the Java applet into a html page, then display it via a UIWebView. I can't get the WebView to display the local html (applet.html in Resources), however. I have linked it up the the WebKit.framework, and can get a http file displayed with:

Code:

[webView setMainFrameURL:@"http://www.google.com"];

But

Code:

[webView setMainFrameURL:@"applet.html"];

fails.
Also, direct addresses work:

Code:

[webView setMainFrameURL:@"file:///Users/Someone/Somewhere/Something.html"];

Here are the details of my project:

iSB.xcodeproj:
[Imported WebKit.framework]
[New class: Controller.h/.m]
Controller.h:

Code:

#import <Foundation/Foundation.h>


@interface Controller : NSObject {
    IBOutlet id webView; //Linked to UIWebView
    IBOutlet id button; //Linked to NSButton
}
-(IBAction)load:(id)sender; //Triggered by the NSButton
@end

Controller.m:

Code:

#import "Controller.h"


@implementation Controller
-(IBAction)load:(id)sender
{
    [webView setMainFrameURL:@"http://www.google.com"]; // Replace Google with applet.html...
}

@end

applet.html (in Resources directory)

Code:

<!DOCTYPE html><html><head></head><body><h1>Hello, world!</h1></body></html>

Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#2 2011-10-10 09:18:32

ZeroLuck
Scratcher
Registered: 2010-02-23
Posts: 500+

Re: Objective-C: Converting Scratch projects to Mac apps (HELP!)

I think your WebView doesn't support Java Applets.
But you can try my Scratch to JAR Converter.


http://3.bp.blogspot.com/-oL2Atzp0Byw/T465vIQ36dI/AAAAAAAAADo/1vqL4PvhkM0/s1600/scratchdachwiki.png

Offline

 

#3 2011-10-10 09:23:11

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Objective-C: Converting Scratch projects to Mac apps (HELP!)

ZeroLuck wrote:

I think your WebView doesn't support Java Applets.
But you can try my Scratch to JAR Converter.

Actually, displaying the poject's website works. But I don't want or need the comments, projects notes, stats, etc.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#4 2011-10-10 15:14:44

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Objective-C: Converting Scratch projects to Mac apps (HELP!)

It's normal: applet.html is only in your resources and the webkit browser displays online pages only (full addresses). Your "applet.html", in this case, is actually searched for in the same directory as the .app.

You'll have to either host the applet.html on some page or find a way to stream the hypertext into the web browser as bytes (it's possible in the .NET WebBrowser, can't remember if there's any way to do it on Macs).

Offline

 

#5 2011-10-14 16:42:29

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: Objective-C: Converting Scratch projects to Mac apps (HELP!)

I have done Objective-C in a while, but if I remember right, there is a method that takes in the name of a file in the resources and output its full path. You could try something like that.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

Board footer