Showing posts with label plugins. Show all posts
Showing posts with label plugins. Show all posts

Tuesday, June 20, 2017

Angular/Ionic not updating an image src when ng-src is empty

The Angular ngSrc directive serves to properly set an image src via Angular. As anything in Angular, it updates the image as soon as the contained Angular expression changes. However, when the ng-src attribute is empty, Angular will not empty the src attribute. To overcome this, use the trick below.
<img ng-src="{{ element.image || '//:0' }}" />

Background

The ngSrc directive explicitly returns when the attribute value is false. As a workaround, set a "blank" image src when the image is empty. As somebody on Stackoverflow writes, //:0 serves this purpose: It adopts the current protocol, omits the hostname and sets the port to zero, which is invalid and should be killed by the network layer.
As a result, Angular should now correctly empty the src attribute when ng-src empties.


Change timeout for connection request in iOS

Code to change ajax request timeout for ios and also for hybrid(Cordova) apps.

Find NSURLRequest in your native code. Change the timeoutInterval value.

  NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:serverURL] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:15.0];



👍

Monday, August 8, 2016

Self Signed SSL Certificates in PhoneGap

Code to allow self signed certs on PhoneGap 

Android:

  • If you are doing development: android:debuggable="true" in the manifest, you should allow the browser to request data from servers with a self-signed or bad SSL cert 
  • If you are releasing an application, you should remove the android:debuggable="true" (Android Market won't let you release with this on anyway) and you will NOT be able to send data to a server with a bad SSL cert 
  • If you don't have this flag set, the default will be what the default is now, which is that you won't be able to send data to servers with a self-signed cert 

iOS: 

Just Add below code at the end of you AppDelegate.m file
@implementation NSURLRequest(DataController)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
    return YES; 
}
@end

Thursday, June 9, 2016

Error: Database location or iosDatabaseLocation value is now mandatory in openDatabase call

if you are using Cordova sqlite plugin you may have this issue while open local DB file.

 _sqlLiteDB = $cordovaSQLite.openDB({ name: "testDB.db", iosDatabaseLocation:'default'}); 
// Works on android but not in iOS

                   

Error: Database location or iosDatabaseLocation value is now mandatory in openDatabase call



Use below to open DB:
window.sqlitePlugin.openDatabase({ name: "testDB.db", location: 2, createFromLocation: 1});


Solution:

if(isAndroid){
                    // Works on android but not in iOS
                    _sqlLiteDB = $cordovaSQLite.openDB({ name: "testDB.db", iosDatabaseLocation:'default'}); 
} else{
                    // Works on iOS 
                    _sqlLiteDB = window.sqlitePlugin.openDatabase({ name: "testDB.db", location: 2, createFromLocation: 1}); 
 }



Friday, June 3, 2016

Warning: sqlite3.c Ambiguous expansion of macro - Xcode - iOS

Plugin: cordova-sqlite-storage

Version: 1.4.1

Warning: sqlite3.c Ambiguous expansion of macro - Xcode - iOS

This issue also helps on native app code. 


Issue Solution:

Open Xcode project Build settings


add “-Wno-ambiguous-macro” into  “Other C flags” 



Wednesday, June 1, 2016

error JSON.stringify()ing argument: RangeError: Invalid Date

There is minor bug in contact plugin in cordova ionic. contact list is loaded with error due to the birthdate field in contact card. Its bad practice to keep minor error in execution of code, It may effect to different OS versions.

error JSON.stringify()ing argument: RangeError: Invalid Date


Cordova Plugin: cordova-plugin-contacts
Verison: 2.1.0 "Contacts"


Open convertUtils.js file  

File Path: plugins/cordova-plugin-contacts/www/convertUtils.js



Find function "toCordovaFormat" and remove below try-catch code.


 try {
         contact.birthday = new Date(parseFloat(value));
} catch (exception){
          console.log("Cordova Contact toCordovaFormat error: exception creating date.");
}

add below code instead of try-catch

if (value !== null) {
        try {
                contact.birthday = new Date(parseFloat(value));
               
                //we might get 'Invalid Date' which does not throw an error
                //and is an instance of Date.
                if (isNaN(contact.birthday.getTime())) {
                       contact.birthday = null;
               }
               
        } catch (exception){
                console.log("Cordova Contact toCordovaFormat error: exception creating date.");
        }
}

Check below screenshot for better understand.




iOS contact card does not have value for "displayName". "displayName" is used for the android devices. So For iOS device, use "name.formatted" instead of "displayName".

Cheers.... Keep Coding... :)








Wednesday, May 25, 2016

Easily Track Javascript File and line number which has error

When all else fails, the issue may be caused by errors in your JavaScript application. A helpful way to determine this is to use the window.onerror function to track down your errors.

Easily Track Javascript File and line number which has error


window.onerror = function (err, fileName, lineNumber) {
   // alert or console.log a message
   alert(fileName, 'Line:', lineNumber, 'Error:', e.message);
};

Parameter info: 
// err: error message
// fileName: which file error occurs in
// lineNumber: what line error occurs on

Monday, September 29, 2014

Woocommerce issue when products and categories has same base path

404 on Product detail page?

Ran into this issue where I needed a url structure such as/shop/<category> and /shop/<category>/<product>/.

/shop/<category>/ works fine but once you click a product you get a nice looking 404 page.

My settings:
Product category base - /shop
Product permalink base -> Custom Structure - /shop/%product_cat%

The Fix:

Set the ‘Product category base’ to shop and the custom product base to /shop/%product_cat%.
Then in your functions.php file add this little snippet:

Tuesday, May 27, 2014

Change User role after payment successful on WooCommerce

Add below action and function on function.php file of the current theme.

add_action('woocommerce_thankyou', 'change_user_role_on_order_success');

function change_user_role_on_order_success($order_id ) {
$order = new WC_Order( $order_id );
$user_id = $order->user_id;
$wp_user_object = new WP_User($user_id);
if($wp_user_object->roles[0] != "administrator"){ // Do not change admin role
wp_update_user( array( 'ID' => $wp_user_object->ID, 'role' => "student" ) );
}
}

Change current user role to administrator.

Add below code to function.php file to change all user role to administrator.

//Change User role to any specific.
 $current_user = wp_get_current_user();
 $wp_user_object = new WP_User($current_user->ID);
 $wp_user_object->set_role('administrator');


Cheers.........

Monday, February 24, 2014

Notify a User when his/her Role has Been Changed to Specific Role

Write below code in function.php file.

function user_role_update( $user_id, $new_role ) {
if ($new_role == 'editor') { 
 $site_url = get_bloginfo('wpurl'); 
 $user_info = get_userdata( $user_id ); 
 $to = $user_info->user_email; 
 $subject = "Congrats your Role changed to ".$new_role."";
 $message = "Hello " .$user_info->display_name . ", your role has changed on ".$site_url.", congratulations you are now an " . $new_role; 
 wp_mail($to, $subject, $message); 
 }
}

add_action( 'set_user_role', 'user_role_update', 10, 2);

Tuesday, November 26, 2013

Add Class to Next and Previous links in Wordpress

Write below code in function.php file to add class on next prev links for pagination

<?php 
add_filter('next_posts_link_attributes', 'posts_next_link_attributes');
add_filter('previous_posts_link_attributes', 'posts_prev_link_attributes');

function posts_next_link_attributes() {
return 'class="nav_next_class"';
}

function posts_prev_link_attributes() {
return 'class="nav_prev_class"';
}
?>

above function will add "nav_next_class" to next link and "nav_prev_class" to previous link.
:)


Friday, April 19, 2013

Get County from User Lat Long

In Mobile application how the server knows about the posted device country and response then as per the location.

Get the current location of the device and use google map api to get user location. Get location from the ipaddress is a worth thing now. because all the internet user use proxy network.

PHP:

<?php

$cur_lat =$_REQUEST['lat'];
$cur_lon = $_REQUEST['lon'];

Wednesday, June 20, 2012

Can not able to drag form fields in Chronoform Wizard Mode

When i develop one site then  I faced issue with the chronoform component. I am not able to create form via wizard edit mode. I tried a lot and then I found one solution for that. and i like to share with you guys.

If you face problem like.. you drag the form elements in the area and its not drag perfect like below image...