Monthly Archives: February 2015
iOS Cordova Get Device Name
Recently in one of my iOS app project, I had a requirement to get device name like “Hiren’s iPhone”. First I thought it’s pretty simple as I checked device API documentation and saw that there is method device.name which should gave device name. I tried that and surprisingly it was returning undefined. I was not sure why it’s not returning result. Then I saw source code and found out actually name property is not added in device API so I decided to add it. In this blog I am going to explain how to do this.
First open your CDVDevice.m file and find following function.
iOS Today App Extension Widget Tap To Open Containing App
Recently I added Today App Extension to one of my iOS app. In that we have a requirement to open containing app when user taps anywhere in app extension view. In this blog I am going to explain how to do this. First you have to add tap gesture recognizer to your main container view. In my case I had UIView as base container view. Inside this view I have added all other views.
So first create iboutlet property for that view. Now create Single Tap Gesture Recognizer.
AppUrlType” as a value. For your application, you can use any valid name. After adding this, you should have following structure in your plist file.
iOS App UI not updating in Main Thread
Recently in one of my projects, I faced a very strange issue. I have an http service call in app which was in background which brings some data. I want to show those data in Textviews in UI. Now the issue was it was not updating UI properly. I had five textviews and five strings in five variables. Out of which it was updating only one Textviews. Rest of the views were not updated. I was not sure what was the issue here as I was updating UI on main thread but still it was not working. See the below code.
iOS Share Data Between iOS App and Today Widget (App Extension)
Recently in one of my projects I implemented a Today Widget for the iOS application. While working on that I faced a situation where I have to get data stored in User Defaults of Main app to Today Widget. In this blog I am going to explain how you can sync data between app and widget. In my case it was simple string data that was stored in user defaults.
For this, first you need to create an app group from Xcode. App group is group of apps which contains main app and an extension. When you create a group from Xcode, it will also create a group in developer portal. For that, first click on project in project explorer and select your main app target in Xcode and go to Capabilities – > App Groups. Initially app groups will be off, first you have to make it on and it will show a pop up window where you can create a new group. Group name always starts with group. prefix. See the image below.
Solution for – Magento cart.totals API Returns Zero After Adding Product
Recently in one of my project I was working with Magento SOAP APIs. Where we have used Magento cart.create API to create Magento cart and adding items to it. Now every time I add items I want to refresh totals. So I used cart_product.add API and after that used cart.totals API to get totals. But strangely it was always returning zero, no matter how many products are there. I tried to find out a solutions for it and did some tests and in one of the test I found out that if after creating a cart if I do operations like setting shipping address or add coupons, it was giving accurate totals. That’s really strange. I tried to find out issue for it but I am not magento expert to finally I came up with following solution. After creating cart, I set dummy billing and shipping address immediately. And then when I add a product and get totals, it was giving me accurate result.
Please note this is not the best solution, but if you want to use you can use this. This will solve your problem. If any magento expert can debug API code and resolve this issue please post solution.
So here is what you have to do.
//Create a Quote
$client = new SoapClient($baseurl.’/api/soap/?wsdl’);
$session = $client->login(USER,PASS);
$quote_id = $client->call( $session, ‘cart.create’, array($_storeId) );
//Add dummy shipping and billing address
$arrAddresses = array(
array(
“mode” => “shipping”,
“firstname” => “testFirstname”,
“lastname” => “testLastname”,
“company” => “testCompany”,
“street” => “testStreet”,
“city” => “testCity”,
“region” => “testRegion”,
“postcode” => “testPostcode”,
“country_id” => “id”,
“telephone” => “0123456789”,
“fax” => “0123456789”,
“is_default_shipping” => 0,
“is_default_billing” => 0
),
array(
“mode” => “billing”,
“firstname” => “testFirstname”,
“lastname” => “testLastname”,
“company” => “testCompany”,
“street” => “testStreet”,
“city” => “testCity”,
“region” => “testRegion”,
“postcode” => “testPostcode”,
“country_id” => “id”,
“telephone” => “0123456789”,
“fax” => “0123456789”,
“is_default_shipping” => 0,
“is_default_billing” => 0
)
);
$resultCustomerAddresses = $client->call($session, “cart_customer.addresses”, array($quote_id, $arrAddresses));
//Now add a product to cart
$resultCartProductAdd = $client->call(
$session,
“cart_product.add”,
array(
$quote_id,
$arrProducts
)
);
//Now get the cart info
$result = $client->call($session, ‘cart.totals’, $quote_id);
echo json_encode($result);
Hope this helps you and solve your problem.
Eclipse Android Java Build Path Error
Hello,
This is small and quick blog on an issue I faced today. I was working on Cordova android project and I updated my Java version and JRE and suddenly I got following error after clean and re building entire work space.
The project cannot be built until build path errors are resolved.
I tried several solutions as usual like removing JAR file references and re add them. Quit eclipse and restart it etc. Still the problem persists. So as all software engineer do, I tried to search on Google and Stackoverflow and find out the same solutions which I already tried. I kept looking for some time and quick applying solutions again and again but this error does not go away. So finally I decided to take backup my current project and start making changes in other copy.
Tried so many things and did refresh workspace so many times. Did clean and rebuild entire workspace but it wasn’t working. Finally I solved it by following step.
1) Go to project explorer and right click on project
2) Select properties.
3) On left side choose Project References.
Once you select this on left, right side you will get your project references with check marks on left side. If you see them un checked as show in following screenshot.
Cordova Android Build Failed (build.xml)- Using old SDK path (Cordova Update Android SDK)
Recently in one of my cordova project I faced an issue. When I created a project, I was using adt-bundle-mac-x86_64-20131030 SDK. Later I upgraded my SDK to new one adt-bundle-mac-x86_64-20140702. Everything was working good since I updated this new SDK path in my .bash_profile file So creating new project was working.
After few months I have to add a new cordova plugin in project which I crated with old sdk. Plugin was added but when I tried to build android project, the build was failed since it was referring to old SDK path which does not exits anymore. I spent an hour to look for a solution to Google but could’t find any solution. Later I checked build.xml file and found out that it was using env.ANDROID_HOME variable to get SDK path. I added following two lines in .bash_profile.


