Skip to content
Open
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
6 changes: 5 additions & 1 deletion android/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
This is the root folder for the Android implementation.
This is the root folder for the Android implementation.
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
data:2016-09-01
1、Update andorid return value bug
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
1 change: 1 addition & 0 deletions android/ponto-sample/assets/ponto_sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
function (params) {
console.log('success with params:');
console.log(params);
alert(JSON.stringify(params));
alert('success');
},
function (params) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.wikia.ponto.sample.modules;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

Expand Down Expand Up @@ -55,8 +58,11 @@ public void sendEmail(String params) {
mContext.startActivity(Intent.createChooser(emailIntent, subject));
}

public void getSomeData() {
public JSONObject getSomeData() {
Log.i("TAG", new Object() {}.getClass().getEnclosingMethod().getName());
Map<String, String> paramsMap = new HashMap<String, String>();
paramsMap.put("msg", "this is some data");
return new JSONObject(paramsMap);
}

}
6 changes: 4 additions & 2 deletions android/ponto/src/com/wikia/ponto/Ponto.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,12 @@ public void request(String execContext, String className, String methodName, Str
Object object = constructor.newInstance(mWebView.getContext());
if (params != null && !params.equalsIgnoreCase(NULL_STRING)) {
Method method = cls.getDeclaredMethod(methodName, String.class);
method.invoke(object, params);
Object retObject = method.invoke(object, params);
if(retObject!=null)responseParams = (JSONObject)retObject;
} else {
Method method = cls.getDeclaredMethod(methodName);
method.invoke(object);
Object retObject = method.invoke(object);
if(retObject!=null)responseParams = (JSONObject)retObject;
}
responseType = RESPONSE_COMPLETE;
} catch (InstantiationException e) {
Expand Down
3 changes: 2 additions & 1 deletion ios/Ponto/Ponto.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,15 @@
name = PontoTests;
productName = PontoTests;
productReference = 6BE468BAA200487C0A00CFAF /* PontoTests.octest */;
productType = "com.apple.product-type.bundle";
productType = "com.apple.product-type.bundle.ocunit-test";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
6BE46A497320EB524FF754F6 /* Project object */ = {
isa = PBXProject;
attributes = {
LastTestingUpgradeCheck = 0700;
};
buildConfigurationList = 6BE46E9490E9050BBD4C5957 /* Build configuration list for PBXProject "Ponto" */;
compatibilityVersion = "Xcode 3.2";
Expand Down
1 change: 1 addition & 0 deletions ios/Ponto/Ponto/PontoDEMOMessaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import <Foundation/Foundation.h>
#import "PontoBaseHandler.h"
#import "PontoDEMOViewController.h"

@interface PontoDEMOMessaging : PontoBaseHandler

Expand Down
11 changes: 10 additions & 1 deletion ios/Ponto/Ponto/PontoDEMOMessaging.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#import "PontoDEMOMessaging.h"
#import "PontoDEMOAppDelegate.h"


@implementation PontoDEMOMessaging {

}
Expand Down Expand Up @@ -47,4 +46,14 @@ - (NSDictionary *)getSomeDataFromHandler {
];
}

- (void)webViewAlertCallback {

// try to call JS method
[[PontoDEMOViewController getPontoDispatcher] invokeMethod:@"show" onTarget:@"Alert" withParams:[NSDictionary dictionaryWithObjectsAndKeys: @"this is callback text",@"text",nil] successBlock:^(id params) {
NSLog(@"success block with params: %@", params);
} errorBlock:^(id params) {
NSLog(@"error block with params: %@", params);
}];
}

@end
2 changes: 2 additions & 0 deletions ios/Ponto/Ponto/PontoDEMOViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
@interface PontoDEMOViewController : UIViewController <PontoDispatcherCallbackDelegate>

@property (strong, nonatomic) IBOutlet UIWebView *webView;

+ (PontoDispatcher *)getPontoDispatcher;
@end
14 changes: 10 additions & 4 deletions ios/Ponto/Ponto/PontoDEMOViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ @interface PontoDEMOViewController ()

@end

static PontoDispatcher *_tempPontoDispatcher = nil;

@implementation PontoDEMOViewController

- (void)viewDidLoad
{

+ (PontoDispatcher *)getPontoDispatcher
{
return _tempPontoDispatcher;
}

- (void)viewDidLoad
{
[super viewDidLoad];


// Create Ponto Dispatcher
self.title = @"Ponto DEMO WebView";
self.pontoDispatcher = [[PontoDispatcher alloc] initWithHandlerClassesPrefix:@"PontoDEMO" andWebView:self.webView];
Expand All @@ -34,12 +39,13 @@ - (void)viewDidLoad
NSLog(@"error block with params: %@", params);
}];


// Load local HTML file
NSString *pathToLocalFile = [[NSBundle mainBundle] pathForResource:@"pontoDemo" ofType:@"html"];
NSURL *localFileURL = [[NSURL alloc] initFileURLWithPath:pathToLocalFile];
NSURLRequest *localFileRequest = [[NSURLRequest alloc] initWithURL:localFileURL];
[self.webView loadRequest:localFileRequest];

_tempPontoDispatcher = self.pontoDispatcher;
}


Expand Down
35 changes: 31 additions & 4 deletions ios/Ponto/Resources/html/pontoDemo.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
<script src="web/src/ponto.js" type="text/javascript"></script>

<script type="text/javascript">

function Alert() {
this.show = function(params) {
console.log('show');
console.log(params.text);
alert(params.text);
};
}

Ponto.PontoBaseHandler.derive(Alert);

Alert.getInstance = function(){
return new Alert();
};

function sendMessage() {
Ponto.invoke(
"Messaging",
Expand All @@ -16,7 +31,6 @@
null);
}


function getSomeDataFromHandler() {
Ponto.invoke(
"Messaging",
Expand All @@ -25,6 +39,7 @@
function (params) {
console.log('success with params:');
console.log(params);
alert(JSON.stringify(params));
alert('success');
},
function (params) {
Expand All @@ -33,8 +48,7 @@
alert('error');
});
}



function testNotExistentMethodInHandler() {
Ponto.invoke(
"Messaging",
Expand All @@ -48,7 +62,6 @@
});
}


function testNotExistentHandler() {
Ponto.invoke(
"NotExistClass",
Expand Down Expand Up @@ -76,6 +89,16 @@
alert(params.message);
});
}


function webViewAlertCallback() {
Ponto.invoke(
"Messaging",
"webViewAlertCallback",
null,
null,
null);
}
</script>
</head>
<body>
Expand All @@ -100,6 +123,10 @@ <h1>Ponto DEMO HTML</h1>
<li>
<button onclick="testNotExistentHandlerWithoutSuccessHandler()">Test not existent handler 2.</button>
</li>

<li>
<button onclick="webViewAlertCallback()">WebView Alert Callback</button>
</li>
</ul>
</body>
</html>
4 changes: 4 additions & 0 deletions ios/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
This is the root folder for the iOS implementation.
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
data:2016-09-04
1、Add iOS Demo WebView Alert Callback.
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*