Skip to content
This repository was archived by the owner on Aug 12, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@
ios/Pods
google-services.json
GoogleService-Info.plist

package-lock.json
20 changes: 14 additions & 6 deletions ios/ScratchJr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
204D80C418A4140600ECBB8B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 204D80AC18A4140600ECBB8B /* UIKit.framework */; };
204D80CC18A4140600ECBB8B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 204D80CA18A4140600ECBB8B /* InfoPlist.strings */; };
204D80CE18A4140600ECBB8B /* ScratchJrTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 204D80CD18A4140600ECBB8B /* ScratchJrTests.m */; };
40F0482024D44803006B2336 /* JsBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 40F0481F24D44803006B2336 /* JsBridge.m */; };
40F0482324D44825006B2336 /* JsRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 40F0482224D44825006B2336 /* JsRequest.m */; };
40F0482E24D4D1D8006B2336 /* View.xib in Resources */ = {isa = PBXBuildFile; fileRef = 40F0482C24D4D1D8006B2336 /* View.xib */; };
7465F19843DCA9DDC62CC852 /* libPods-ScratchJr Free.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7ACBA0233542F96AC72D4D7E /* libPods-ScratchJr Free.a */; };
A7FDEB52BFEDCD9E4520FF89 /* libPods-ScratchJrTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 512C88D0E9938AB5972ACF38 /* libPods-ScratchJrTests.a */; };
D92D0F951C33381B00C573AD /* MessageUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2001BEB918E237AE008E563F /* MessageUI.framework */; };
Expand All @@ -22,7 +25,6 @@
D92D0F9A1C33381B00C573AD /* libsqlite3.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 20B2226E18A46327003BDE44 /* libsqlite3.0.dylib */; };
D92D0F9D1C33381B00C573AD /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 20B2226818A4404B003BDE44 /* Settings.bundle */; };
D92D0F9E1C33381B00C573AD /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 204D80B118A4140600ECBB8B /* InfoPlist.strings */; };
D92D0F9F1C33381B00C573AD /* View.xib in Resources */ = {isa = PBXBuildFile; fileRef = 204D80DC18A4195E00ECBB8B /* View.xib */; };
D92D0FCA1C3346D200C573AD /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D92D0FB31C33469A00C573AD /* AppDelegate.m */; };
D92D0FCB1C3346D200C573AD /* CameraMask.m in Sources */ = {isa = PBXBuildFile; fileRef = D92D0FB41C33469A00C573AD /* CameraMask.m */; };
D92D0FCC1C3346D200C573AD /* CameraView.m in Sources */ = {isa = PBXBuildFile; fileRef = D92D0FB51C33469A00C573AD /* CameraView.m */; };
Expand Down Expand Up @@ -62,10 +64,12 @@
204D80C918A4140600ECBB8B /* ScratchJrTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "ScratchJrTests-Info.plist"; sourceTree = "<group>"; };
204D80CB18A4140600ECBB8B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
204D80CD18A4140600ECBB8B /* ScratchJrTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ScratchJrTests.m; sourceTree = "<group>"; };
204D80DC18A4195E00ECBB8B /* View.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = View.xib; sourceTree = "<group>"; };
20B2226818A4404B003BDE44 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = SOURCE_ROOT; };
20B2226E18A46327003BDE44 /* libsqlite3.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.0.dylib; path = usr/lib/libsqlite3.0.dylib; sourceTree = SDKROOT; };
20B2227818A53688003BDE44 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
40F0481F24D44803006B2336 /* JsBridge.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JsBridge.m; sourceTree = "<group>"; };
40F0482224D44825006B2336 /* JsRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JsRequest.m; sourceTree = "<group>"; };
40F0482C24D4D1D8006B2336 /* View.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = View.xib; path = src/View.xib; sourceTree = "<group>"; };
512C88D0E9938AB5972ACF38 /* libPods-ScratchJrTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ScratchJrTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
5A3230A01AEC02BC09345F16 /* Pods-ScratchJrTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ScratchJrTests.debug.xcconfig"; path = "Target Support Files/Pods-ScratchJrTests/Pods-ScratchJrTests.debug.xcconfig"; sourceTree = "<group>"; };
72E2C9BF3BE9F67099F0180F /* Pods-ScratchJrTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ScratchJrTests.release.xcconfig"; path = "Target Support Files/Pods-ScratchJrTests/Pods-ScratchJrTests.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -166,7 +170,7 @@
children = (
D92D0FC91C3346AC00C573AD /* src */,
204D80AF18A4140600ECBB8B /* Supporting Files */,
204D80DC18A4195E00ECBB8B /* View.xib */,
40F0482C24D4D1D8006B2336 /* View.xib */,
);
path = ScratchJr;
sourceTree = "<group>";
Expand Down Expand Up @@ -256,6 +260,8 @@
D92D0FE01C3347D100C573AD /* IO */ = {
isa = PBXGroup;
children = (
40F0481F24D44803006B2336 /* JsBridge.m */,
40F0482224D44825006B2336 /* JsRequest.m */,
D92D0FB61C33469A00C573AD /* Database.m */,
D92D0FB71C33469A00C573AD /* IO.m */,
);
Expand Down Expand Up @@ -356,7 +362,7 @@
D92D0F9D1C33381B00C573AD /* Settings.bundle in Resources */,
D965E3971C3EC63A005D792F /* Free-Images.xcassets in Resources */,
D92D0F9E1C33381B00C573AD /* InfoPlist.strings in Resources */,
D92D0F9F1C33381B00C573AD /* View.xib in Resources */,
40F0482E24D4D1D8006B2336 /* View.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -438,7 +444,9 @@
files = (
D92D0FCD1C3346DC00C573AD /* Database.m in Sources */,
D92D0FCE1C3346DC00C573AD /* IO.m in Sources */,
40F0482024D44803006B2336 /* JsBridge.m in Sources */,
D92D0FCF1C3346DC00C573AD /* main.m in Sources */,
40F0482324D44825006B2336 /* JsRequest.m in Sources */,
D92D0FD01C3346DC00C573AD /* RecordSound.m in Sources */,
D92D0FD11C3346DC00C573AD /* ScratchJr.m in Sources */,
D92D0FD21C3346DC00C573AD /* ViewController.m in Sources */,
Expand Down Expand Up @@ -644,7 +652,7 @@
"COCOAPODS=1",
);
INFOPLIST_FILE = "$(SRCROOT)/../editions/free/Free-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
PRODUCT_BUNDLE_IDENTIFIER = edu.mitmedialab.scratchjrfree;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
Expand All @@ -669,7 +677,7 @@
"COCOAPODS=1",
);
INFOPLIST_FILE = "$(SRCROOT)/../editions/free/Free-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
PRODUCT_BUNDLE_IDENTIFIER = edu.mitmedialab.scratchjrfree;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
Expand Down
190 changes: 190 additions & 0 deletions ios/ScratchJr/JsBridge.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
//
// JsBridge.m
// ScratchJr Free
//
// Created by Yueyu on 2020/7/31.
// Copyright © 2020 Playful Invention Company. All rights reserved.
//

#import "ScratchJr.h"
#import <WebKit/WebKit.h>
@import Firebase;

@implementation JsBridge

-(void) userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
{
NSDictionary *dict = (NSDictionary *)message.body;

JsRequest *request = [[JsRequest alloc] initWithDictionary:dict];

NSString *method = [request.method stringByAppendingString:@":"];
SEL selector = NSSelectorFromString(method);
if (![self respondsToSelector:selector]) {
NSLog(@"method %@ not exists", request.method);
return;
}
// [self performSelector:selector withObject:request];
// to disable warning: PerformSelector may cause a leak because its selector is unknown
// thanks wbyoung for https://stackoverflow.com/a/20058585
IMP imp = [self methodForSelector:selector];
void (*func)(id, SEL, JsRequest *) = (void *)imp;
func(self, selector, request);
}

-(void) askForPermission: (JsRequest *) request
{
[RecordSound setPermission];
[request callback:@"ok"];
}

-(void) database_stmt: (JsRequest *) request {
[request callback:[Database stmt:request.params[0]]];
}

-(void) database_query: (JsRequest *) request {
[request callback:[Database query:request.params[0]]];
}

-(void) io_getmd5: (JsRequest *) request {
[request callback:[IO getMD5:request.params[0]]];
}

-(void) io_getsettings: (JsRequest *) request {
[request callback:[IO getsettings]];
}

-(void) io_cleanassets: (JsRequest *) request {
[IO cleanassets: request.params[0]];
[request callback:@"ok"];
}

-(void) io_setfile: (JsRequest *) request {
[request callback:[IO setfile:request.params[0]:request.params[1]]];
}

-(void) io_getfile: (JsRequest *) request {
[request callback:[IO getfile:request.params[0]]];
}

-(void) io_setmedia: (JsRequest *) request {
[request callback:[IO setmedia:request.params[0] :request.params[1]]];
}

-(void) io_setmedianame: (JsRequest *) request {
[request callback:[IO setmedianame:request.params[0] :request.params[1] :request.params[2]]];
}

-(void) io_getmedia: (JsRequest *) request {
[request callback:[IO getmedia:request.params[0]]];
}

-(void) io_getmediadata: (JsRequest *) request {
int offset = [request.params[1] intValue];
int length = [request.params[2] intValue];
NSString *key = [NSString stringWithFormat:@"%@", request.params[0]];
[request callback:[IO getmediadata:key :offset :length]];
}

-(void) io_getmedialen: (JsRequest *) request {
NSString *key = [NSString stringWithFormat:@"%@", request.params[1]];
[request callback:[IO getmedialen:request.params[0] :key]];
}

-(void) io_getmediadone: (JsRequest *) request {
[request callback:[IO getmediadone:request.params[0]]];
}

-(void) io_remove: (JsRequest *) request {
[request callback:[IO remove:request.params[0]]];
}

-(void) io_registersound: (JsRequest *) request {
[request callback:[IO registerSound:request.params[0] :request.params[1]]];
}

-(void) io_playsound: (JsRequest *) request {
[request callback:[IO playSound:request.params[0]]];
}

-(void) io_stopsound: (JsRequest *) request {
[request callback:[IO stopSound:request.params[0]]];
}

-(void) recordsound_recordstart: (JsRequest *) request {
[request callback:[RecordSound startRecord]];
}

-(void) recordsound_recordstop: (JsRequest *) request {
[request callback:[RecordSound stopRecording]];
}

-(void) recordsound_volume: (JsRequest *) request {
[request callback:[NSString stringWithFormat:@"%f", [RecordSound getVolume]]];
}

-(void) recordsound_startplay: (JsRequest *) request {
[request callback:[RecordSound startPlay]];
}

-(void) recordsound_stopplay: (JsRequest *) request {
[request callback:[RecordSound stopPlay]];
}

-(void) recordsound_recordclose: (JsRequest *) request {
[request callback:[RecordSound recordclose:request.params[0]]];
}

-(void) scratchjr_cameracheck: (JsRequest *) request {
[request callback:[ScratchJr cameracheck]];
}

-(void) scratchjr_has_multiple_cameras: (JsRequest *) request {
[request callback:@"YES"];
}

-(void) scratchjr_startfeed: (JsRequest *) request {
[request callback:[ScratchJr startfeed: request.params[0]]];
}

-(void) scratchjr_stopfeed: (JsRequest *) request {
[request callback:[ScratchJr stopfeed]];
}

-(void) scratchjr_choosecamera: (JsRequest *) request {
[request callback:[ScratchJr choosecamera:request.params[0]]];
}

-(void) scratchjr_captureimage: (JsRequest *) request {
[request callback:[ScratchJr captureimage:request.params[0]]];
}

-(void) sendSjrUsingShareDialog: (JsRequest *) request {
int shareType = [request.params[3] intValue];
NSString *res = [IO sendSjrUsingShareDialog:request.params[0] :request.params[1] :request.params[2] :shareType : request.params[4]];
[request callback:res];
}

- (void) hideSplash: (JsRequest *) request {
[request callback:[ScratchJr hideSplash:nil]];
}

-(void) analyticsEvent: (JsRequest *) request {
[FIRAnalytics logEventWithName:request.params[1] // action
parameters:@{
kFIRParameterItemName:request.params[2], // label
kFIRParameterItemCategory:request.params[0] // category
}];
}

-(void) setAnalyticsPlacePref: (JsRequest *) request {
[FIRAnalytics setUserPropertyString:request.params[0] forName:@"place_preference"];
[request callback:@"ok"];
}

// iPad name (used for information in the name/sharing dialog to help people using Airdrop)
- (void) deviceName: (JsRequest *) request {
[request callback:[[UIDevice currentDevice] name]];
}

@end
33 changes: 33 additions & 0 deletions ios/ScratchJr/JsRequest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// JsRequest.m
// ScratchJr Free
//
// Created by Yueyu on 2020/7/31.
// Copyright © 2020 Playful Invention Company. All rights reserved.
//

#import "ScratchJr.h"

@implementation JsRequest

- (instancetype)initWithDictionary:(NSDictionary *)dictionary {
self = [super init];
self.method = dictionary[@"method"];
self.callId = dictionary[@"id"];
self.params = dictionary[@"params"];
return self;
}

- (void) callback:(NSString *)res {
NSString *js = nil;
if ([res hasPrefix:@"["] || [res hasPrefix:@"{"]) {
js = [NSString stringWithFormat:@"iOS.resolve('%@', %@);", self.callId, res];
} else {
js = [NSString stringWithFormat:@"iOS.resolve('%@', '%@');", self.callId, res];
}
dispatch_async(dispatch_get_main_queue(), ^{
[ViewController.webview evaluateJavaScript:js completionHandler:nil];
});
}

@end
20 changes: 0 additions & 20 deletions ios/ScratchJr/View.xib

This file was deleted.

4 changes: 2 additions & 2 deletions ios/ScratchJr/src/IO.m
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ + (void)soundEnded:(NSTimer*)timer {
NSString *soundName = [[timer userInfo] objectForKey:@"soundName"];
if (sounds[soundName] == nil) return;
NSString *callback = [NSString stringWithFormat:@"iOS.soundDone('%@');", soundName];
UIWebView *webview = [ViewController webview];
WKWebView *webview = [ViewController webview];
dispatch_async(dispatch_get_main_queue(), ^{
[webview stringByEvaluatingJavaScriptFromString:callback];
[webview evaluateJavaScript:callback completionHandler:nil];
});
}

Expand Down
Loading