Cordova PayPal Plugin integration iOS issue - javascript

I have a mobile app with com.paypal.cordova.mobilesdk v3.5.0
I am getting the following error when creating payment in iOS.
Please also note that the app crashes and closes immediately when not in debug mode.
2018-09-02 20:48:29.853486+0200 MyHurryApp[631:122102] -[NSNull length]: unrecognized selector sent to instance 0x1b69ef878
2018-09-02 20:48:29.856680+0200 MyHurryApp[631:122102] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x1b69ef878'
*** First throw call stack:
(0x1843bad8c 0x1835745ec 0x1843c8098 0x1843c05c8 0x1842a641c 0x102ad75e8 0x1028c1c20 0x1033211dc 0x10332119c 0x103325d2c 0x184363070 0x184360bc8 0x184280da8 0x186266020 0x18e2a0758 0x1028beb90 0x183d11fc0)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The line causing this crash seems to be:
[PayPalMobile preconnectWithEnvironment:environmentToUse];
```
- (void)prepareToRender:(CDVInvokedUrlCommand *)command {
[self.commandDelegate runInBackground:^{
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
NSString *environment = [command.arguments objectAtIndex:0];
NSString *environmentToUse = [self parseEnvironment:environment];
if (environmentToUse) {
// save configuration
PayPalConfiguration *configuration = [self getPayPalConfigurationFromDictionary:[command.arguments objectAtIndex:1]];
self.configuration = configuration;
// do preconnect
dispatch_async(dispatch_get_main_queue(), ^{
[PayPalMobile preconnectWithEnvironment:environmentToUse];
});
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:#"The provided environment is not supported"];
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
```
In other forums I've seen suggestions that you should convert the payment amount to string, which I did however the issue is still there. Click here for example
Any other suggestions please?

Citing from the plugins readme:
Important: PayPal Mobile SDKs are now Deprecated and only existing integrations are supported. For all new integrations, use Braintree Direct in supported countries. In other countries, use Express Checkout and choose the Braintree SDK integration option.
The same warning is also shown at the paypal developer page.
So I guess your app is crashing at this:
[PayPalMobile preconnectWithEnvironment:environmentToUse];
position because you are trying to connect with a new environment, which is not supported anymore.
Most apps use the in-app-browser for realizing PayPal checkouts now.

Related

VS2015 Cordova Sms Plugin Sms.Send doesn't work in Index.JS (ondeviceReady)

I'm new to Cordova, any help would be appreciated.
I created a new Cordova Project in VS2015 and added the Cordova SMS plugin to my project (https://www.npmjs.com/package/cordova-sms-plugin).
I added this code to /www/scripts/index.js function onDeviceReady (as per documentiation for plugin):
function onDeviceReady() {
// Handle the Cordova pause and resume events
document.addEventListener( 'pause', onPause.bind( this ), false );
document.addEventListener( 'resume', onResume.bind( this ), false );
var numberString = "aoeuaeu";
var bypassAppChooser = true;
//CONFIGURATION
var options = {
replaceLineBreaks: false,
android: {
intent: 'INTENT' // send SMS with the native android SMS messaging
}
};
var successSMS = function () { alert('Message sent successfully'); };
var errorSMS = function (e) { alert('Message Failed:' + e); };
sms.send("0811231234", "Testing123", options, successSMS, errorSMS);
I debug the project using Debug, Android, Ripple - Nexus (Galaxy) selected options. When I place a breakpoint on the sms.send line of code and I add a watch for 'sms.send', I can see the object exists.
When I single step, this line in sms.js seems to be the last line that executes:
// fire
exec(
success,
failure,
'Sms',
'send', [phone, message, androidIntent, replaceLineBreaks]
);
I then get the following error message in Ripple:
'Sms.send We seem to be missing some stuff :( What is kinda cool though you can fill in the textarea to pass a json object to the callback you want to execute).'
I can see that all of the objects in that line is defined (success, failure, phone, message, androidIntent, replaceLineBreaks). When I 'step into' this line, it continues to execute code in ripple.js, but it becomes hard to follow for a person, since there are no line breaks in this file.
What am I doing wrong? I've read through all the documentation I can find & searched stackoverflow questions and can't seem to find any solutions to the problem.
I've uploaded this entire project (zipped), which can be downloaded at:
https://drive.google.com/file/d/0BwWgTMh-JLbfNHV0MlE5Yk5IZ3M/view?usp=sharing
Thanks in advance
Thank you Cordova team at Microsoft for helping me with an answer:
"Ripple has the ability to emulate some but not all plugins. SMS is not one of the plugins that it can fully emulate. However, in the message that pops up, you do have the ability to hit the Success or Fail buttons which will report back to the app that it was successful or not in sending the SMS. While that doesn’t actually send a message, it does let you test your app to see how it behaves for different results.
I tried the bit of sample code you included in the first email. In Ripple, I was able to change the alert by hitting the different buttons.
Trying other deployment methods, in both the VS Android Emulator and the Google Emulator they showed failure alert messages that they don’t support SMS messages. I then launched it on an Android phone device and it said it was successful.
So I believe your options are mainly using Ripple to fake sending of messages or using a device for testing."

What is WKErrorDomain error 4 from WKWebView

fatal error: LPWebView encounters an error: Error Domain=WKErrorDomain Code=4
"A JavaScript exception occurred" UserInfo=0x79d9c700
{NSLocalizedDescription=A JavaScript exception occurred}
I encountered this error when I tried to evaluate a JavaScript function with WKWebView.
I used loadHTMLString to load a template to the webview.
let bundle = NSBundle.mainBundle()
if let editorURL = bundle.URLForResource(self.kTemplateName,
withExtension: "html") {
var error : NSError?
//get html string from editor.html
if let htmlString = String(contentsOfURL: editorURL, encoding: NSUTF8StringEncoding, error: &error){
if error != nil {
assertionFailure("error encountered reading html string for \(error)")
} else {
self.loadHTMLString(htmlString, baseURL: bundle.bundleURL)
}
}
} else {
assertionFailure("LPWebView template not found")
}
I wonder what this error code means and how to solve it?
Thank you very much!
So if we dig into the headers:
/*! #constant WKErrorDomain Indicates a WebKit error. */
#availability(iOS, introduced=8.0)
let WKErrorDomain: String
/*! #enum WKErrorCode
#abstract Constants used by NSError to indicate errors in the WebKit domain.
#constant WKErrorUnkcnown Indicates that an unknown error occurred.
#constant WKErrorWebContentProcessTerminated Indicates that the Web Content process was terminated.
#constant WKErrorWebViewInvalidated Indicates that the WKWebView was invalidated.
#constant WKErrorJavaScriptExceptionOccurred Indicates that a JavaScript exception occurred.
*/
#availability(iOS, introduced=8.0)
enum WKErrorCode : Int {
case Unknown
case WebContentProcessTerminated
case WebViewInvalidated
case JavaScriptExceptionOccurred
}
Error code 4 would corresponds to JavaScriptExceptionOccurred, or WKErrorJavaScriptExceptionOccurred.
In other words, the JavaScript function causes some error.
Probably not more here that you couldn't guess already. For resolution, I would suggest using the developer features of a web browser such as Safari, loading the HTML and debugging.
In fact, as explained in the WWDC 2014 video, "Introducing the Modern WebKit API", your desktop Safari browser can "inspect the WKWebView using the Safari web inspector, including any user scripts that you've injected."
To use this, while the WKWebView is loaded in memory in your running app on the iOS simulator, open the desktop Safari browser and access Develop on the top menu bar then iOS Simulator. That will show a drop down of the web view's document objects.
For more info on debugging JavaScript, take a look at Web Inspector: Understanding Stack Traces

IBM Worklight:Call IOS Nativecode When plugin is Created

I am trying to integrate iOS Native code to my Worklight application.
I Have created a Cordova plug-in with the below code:
HelloWorldPlugin.h
#import <Foundation/Foundation.h>
#import <Cordova/CDV.h>
#interface HelloWorldPlugin : CDVPlugin
{
UINavigationController *navi;
}
-(void)sayHello:(CDVInvokedUrlCommand*)command;
HelloWorldPlugin.m is
-(void)sayHello:(CDVInvokedUrlCommand *)command
{
NSString *responseString=[NSString stringWithFormat:#"Hello........World %#",
[command.arguments objectAtIndex:0]];
CDVPluginResult *pluginResult=[CDVPluginResult
resultWithStatus:CDVCommandStatus_OK mes sageAsString:responseString];
[self.commandDelegate sendPluginResult:pluginResult
callbackId:command.callbackId];
}
The above code is working. Next, I have created a BarcodeScannerViewController Class. It contains: BarcodeScannerViewController.h, BarcodeScannerViewController.m and BarcodeScannerViewController.xib.
I need to call the BarcodeViewController so that the functionality of barcode should happen.
In above HelloWorldPlugin.m I have modified code as below to move to BarcodeScannerViewController
#implementation HelloWorldPlugin
-(void)sayHello:(CDVInvokedUrlCommand *)command
{
NSString *responseString=[NSString stringWithFormat:#"Hello........World %#",
[command.arguments objectAtIndex:0]];
CDVPluginResult *pluginResult=[CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsString:responseString];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
BarCodeScannerViewController *view=[[BarCodeScannerViewController alloc]init];
navi=[[UINavigationController alloc] initWithRootViewController:view];
}
But i am not able to move and getting log error as
2014-07-11 10:06:23.660 HelloWorld[548:60b] THREAD WARNING:
['HelloWorldPlugin'] took
'214928.292969' ms. Plugin should use a background thread.
2014-07-11 10:06:23.666 HelloWorld[548:4207] void SendDelegateMessage(NSInvocation *):
delegate (webView:decidePolicyForNavigationAction:request:frame:decisionListener:)
failed
to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode
One of the .zip files you've uploaded (in the comments) is no longer available, so I cannot test it myself, but my suggestion is to implement this with the Send Action feature available in Worklight 6.2.
This way the implementation is very clean and straight forward. The basic premise is:
From the application's JavaScript you will invoke an "action"
This action will basically be to display your View Controller
When you're done, you return from your custom View Controller back to the Worklight-provided View Controller (the web app...)
You can read about Send Action as well as see an example implementation, here:
Sending actions and data objects from JavaScript code to native code
Sending actions and data objects from native code to JavaScript code
Question with example code (JS to native)
Example project (native to JS)

PhoneGap iOS + DOM Exception 18

I'm going a window.onerror "SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent." Each time I load my iOS PhoneGap app. THe app uses local storage and webSQL. I have isolated this error to be throw when I open my db using: db = window.openDatabase("db", "1.0", "Test DB", 1000000);
I haven't had this issue before and my code hasn't changed - this just came out of now where. I've been looking at the iOS 5.1 web view storage bugs and fear it may be related.
Help?
It's a confirmed Apple bug in iOS 5.1. Details here in this PhoneGap/Cordova issue tracker: https://issues.apache.org/jira/browse/CB-347
I have used this and It is working perfectly.Try this
try {
if (!window.openDatabase) {
alert('not supported');
} else {
var shortName = 'WineDatabase';
var version = '1.0';
var displayName = 'PhoneGap Test Database';
var maxSize = 655367; // in bytes
mydb = openDatabase(shortName, version, displayName, maxSize);
}
} catch(e) {
// Error handling code goes here.
if (e == INVALID_STATE_ERR) {
// Version number mismatch.
alert("Invalid database version.");
} else {
alert("Unknown error "+e+".");
}
return;
}
EDIT:
At that time I was using Phonegap on ios.So I hadn't get it,Now on blackberry phonegap I am getting same issue and and found the cause that: while datacable is plugged app is not able to write anything on SDCard.So I unplugged it and run working fine.Sorry buddy not the solution for ios But people who are searching this issue for blackberry can use this solution.

Detecting JavaScript errors in a UIWebView [duplicate]

I need to have my iPhone Objective-C code catch Javascript errors in a UIWebView. That includes uncaught exceptions, syntax errors when loading files, undefined variable references, etc.
This is for a development environment, so it doesn't need to be SDK-kosher. In fact, it only really needs to work on the simulator.
I've already found used some of the hidden WebKit tricks to e.g. expose Obj-C objects to JS and to intercept alert popups, but this one is still eluding me.
[NOTE: after posting this I did find one way using a debugging delegate. Is there a way with lower overhead, using the error console / web inspector?]
I have now found one way using the script debugger hooks in WebView (note, NOT UIWebView). I first had to subclass UIWebView and add a method like this:
- (void)webView:(id)webView windowScriptObjectAvailable:(id)newWindowScriptObject {
// save these goodies
windowScriptObject = newWindowScriptObject;
privateWebView = webView;
if (scriptDebuggingEnabled) {
[webView setScriptDebugDelegate:[[YourScriptDebugDelegate alloc] init]];
}
}
Next you should create a YourScriptDebugDelegate class that contains methods like these:
// in YourScriptDebugDelegate
- (void)webView:(WebView *)webView didParseSource:(NSString *)source
baseLineNumber:(unsigned)lineNumber
fromURL:(NSURL *)url
sourceId:(int)sid
forWebFrame:(WebFrame *)webFrame
{
NSLog(#"NSDD: called didParseSource: sid=%d, url=%#", sid, url);
}
// some source failed to parse
- (void)webView:(WebView *)webView failedToParseSource:(NSString *)source
baseLineNumber:(unsigned)lineNumber
fromURL:(NSURL *)url
withError:(NSError *)error
forWebFrame:(WebFrame *)webFrame
{
NSLog(#"NSDD: called failedToParseSource: url=%# line=%d error=%#\nsource=%#", url, lineNumber, error, source);
}
- (void)webView:(WebView *)webView exceptionWasRaised:(WebScriptCallFrame *)frame
sourceId:(int)sid
line:(int)lineno
forWebFrame:(WebFrame *)webFrame
{
NSLog(#"NSDD: exception: sid=%d line=%d function=%#, caller=%#, exception=%#",
sid, lineno, [frame functionName], [frame caller], [frame exception]);
}
There is probably a large runtime impact for this, as the debug delegate can also supply methods to be called for entering and exiting a stack frame, and for executing each line of code.
See http://www.koders.com/noncode/fid7DE7ECEB052C3531743728D41A233A951C79E0AE.aspx for the Objective-C++ definition of WebScriptDebugDelegate.
Those other methods:
// just entered a stack frame (i.e. called a function, or started global scope)
- (void)webView:(WebView *)webView didEnterCallFrame:(WebScriptCallFrame *)frame
sourceId:(int)sid
line:(int)lineno
forWebFrame:(WebFrame *)webFrame;
// about to execute some code
- (void)webView:(WebView *)webView willExecuteStatement:(WebScriptCallFrame *)frame
sourceId:(int)sid
line:(int)lineno
forWebFrame:(WebFrame *)webFrame;
// about to leave a stack frame (i.e. return from a function)
- (void)webView:(WebView *)webView willLeaveCallFrame:(WebScriptCallFrame *)frame
sourceId:(int)sid
line:(int)lineno
forWebFrame:(WebFrame *)webFrame;
Note that this is all hidden away in a private framework, so don't try to put this in code you submit to the App Store, and be prepared for some hackery to get it to work.
I created a nice little drop-in category that you can add to your project...
It is based on Robert Sanders solution. Kudos.
You can dowload it here:
UIWebView+Debug
This should make it a lot easier to debug you UIWebView :)
I used the great solution proposed from Robert Sanders: How can my iPhone Objective-C code get notified of Javascript errors in a UIWebView?
That hook for webkit works fine also on iPhone. Instead of standard UIWebView I allocated derived MyUIWebView. I needed also to define hidden classes inside MyWebScriptObjectDelegate.h:
#class WebView;
#class WebFrame;
#class WebScriptCallFrame;
Within the ios sdk 4.1 the function:
- (void)webView:(id)webView windowScriptObjectAvailable:(id)newWindowScriptObject
is deprecated and instead of it I used the function:
- (void)webView:(id)sender didClearWindowObject:(id)windowObject forFrame:(WebFrame*)frame
Also, I get some annoying warnings like "NSObject may not respond -windowScriptObject" because the class interface is hidden. I ignore them and it works nice.
One way that works during development if you have Safari v 6+ (I'm uncertain what iOS version you need) is to use the Safari development tools and hook into the UIWebView through it.
In Safari: Enable the Develop Menu (Preferences > Advanced > Show Develop menu in menu bar)
Plug your phone into the computer via the cable.
List item
Load up the app (either through xcode or just launch it) and go to the screen you want to debug.
Back in Safari, open the Develop menu, look for the name of your device in that menu (mine is called iPhone 5), should be right under User Agent.
Select it and you should see a drop down of the web views currently visible in your app.
If you have more than one webview on the screen you can try to tell them apart by rolling over the name of the app in the develop menu. The corresponding UIWebView will turn blue.
Select the name of the app, the develop window opens and you can inspect the console. You can even issue JS commands through it.
Straight Forward Way: Put this code on top of your controller/view that is using the UIWebView
#ifdef DEBUG
#interface DebugWebDelegate : NSObject
#end
#implementation DebugWebDelegate
#class WebView;
#class WebScriptCallFrame;
#class WebFrame;
- (void)webView:(WebView *)webView exceptionWasRaised:(WebScriptCallFrame *)frame
sourceId:(int)sid
line:(int)lineno
forWebFrame:(WebFrame *)webFrame
{
NSLog(#"NSDD: exception: sid=%d line=%d function=%#, caller=%#, exception=%#",
sid, lineno, [frame functionName], [frame caller], [frame exception]);
}
#end
#interface DebugWebView : UIWebView
id windowScriptObject;
id privateWebView;
#end
#implementation DebugWebView
- (void)webView:(id)sender didClearWindowObject:(id)windowObject forFrame:(WebFrame*)frame
{
[sender setScriptDebugDelegate:[[DebugWebDelegate alloc] init]];
}
#end
#endif
And then instantiate it like this:
#ifdef DEBUG
myWebview = [[DebugWebView alloc] initWithFrame:frame];
#else
myWebview = [[UIWebView alloc] initWithFrame:frame];
#endif
Using #ifdef DEBUG ensures that it doesn't go in the release build, but I would also recommend commenting it out when you're not using it since it has a performance impact. Credit goes to Robert Sanders and Prcela for the original code
Also if using ARC you may need to add "-fno-objc-arc" to prevent some build errors.
I have created an SDK kosher error reporter that includes:
The error message
The name of the file the error happens in
The line number the error happens on
The JavaScript callstack including parameters passed
It is part of the QuickConnectiPhone framework available from the sourceForge project
There is even an example application that shows how to send an error message to the Xcode terminal.
All you need to do is to surround your JavaScript code, including function definitions, etc. with try catch. It should look like this.
try{
//put your code here
}
catch(err){
logError(err);
}
It doesn't work really well with compilation errors but works with all others. Even anonymous functions.
The development blog is here
is here and includes links to the wiki, sourceForge, the google group, and twitter. Maybe this would help you out.
I have done this in firmware 1.x but not 2.x.
Here is the code I used in 1.x, it should at least help you on your way.
// Dismiss Javascript alerts and telephone confirms
/*- (void)alertSheet:(UIAlertSheet*)sheet buttonClicked:(int)button
{
if (button == 1)
{
[sheet setContext: nil];
}
[sheet dismiss];
}*/
// Javascript errors and logs
- (void) webView: (WebView*)webView addMessageToConsole: (NSDictionary*)dictionary
{
NSLog(#"Javascript log: %#", dictionary);
}
// Javascript alerts
- (void) webView: (WebView*)webView runJavaScriptAlertPanelWithMessage: (NSString*) message initiatedByFrame: (WebFrame*) frame
{
NSLog(#"Javascript Alert: %#", message);
UIAlertSheet *alertSheet = [[UIAlertSheet alloc] init];
[alertSheet setTitle: #"Javascript Alert"];
[alertSheet addButtonWithTitle: #"OK"];
[alertSheet setBodyText:message];
[alertSheet setDelegate: self];
[alertSheet setContext: self];
[alertSheet popupAlertAnimated:YES];
}
See exception handling in iOS7:
http://www.bignerdranch.com/blog/javascriptcore-example/
[context setExceptionHandler:^(JSContext *context, JSValue *value) {
NSLog(#"%#", value);
}];
First setup WebViewJavascriptBridge ,
then override console.error function.
In javascript
window.originConsoleError = console.error;
console.error = (msg) => {
window.originConsoleError(msg);
bridge.callHandler("sendConsoleLogToNative", {
action:action,
message:message
}, null)
};
In Objective-C
[self.bridge registerHandler:#"sendConsoleLogToNative" handler:^(id data, WVJBResponseCallback responseCallback) {
NSString *action = data[#"action"];
NSString *msg = data[#"message"];
if (isStringValid(action)){
if ([#"console.error" isEqualToString:action]){
NSLog(#"JS error :%#",msg);
}
}
}];
A simpler solution for some cases might be to just add Firebug Lite to the Web page.

Categories

Resources