Tuesday, December 4, 2012

Jquery : Linking external .js file


If your external js method is not called then there should be 2 problems.
Problem 1
It looks like jquery.js contains the code you wrote that depends on jQuery.
Solution:
You need to load jQuery before your external js file.


Problem 2
 User defined function is not in $(function() {
/* your function */
});
$(document).ready() function. Everything inside it will load as soon as the DOM is loaded and before the page contents are loaded.
 $(document).ready(function() {
   // some code here
 });

$(document).ready(function() {
   // other code here
 });

 $(document).ready(),  you can write $(function(){ ... }) instead, like so: 
  $(function() {
   // do something on document ready
 });
 
Solution:

Add the below code.
$(function ()  
 /* your function */ 
});

For more Ref: jquery doc

Thursday, November 29, 2012

Android: Solution for "proguard returned with error code 1" and “Conversion to Dalvik format failed with error 1"


ProGuard is a free Java class file shrinker, optimizer, obfuscator, and preverifier. It detects and removes unused classes, fields, methods, and attributes. It optimizes bytecode and removes unused instructions. It renames the remaining classes, fields, and methods using short meaningless names. Finally, it preverifies the processed code for Java 6 or for Java Micro Edition.

Solution for few errors like “Proguard returned with error code 1.”  and “Conversion to Dalvik format failed with error 1” is to download from http://sourceforge.net/projects/proguard/files/proguard/  and just copy the ProGuard jars to android-sdk/tools/proguard/lib

Conversion to Dalvik format failed with error 1
This error may have various causes, but if dx is tripping over some code processed by ProGuard, you should make sure that you are using the latest version of ProGuard. You can just copy the ProGuard jars to android-sdk/tools/proguard/lib.

For more details refer: Troubleshooting Link

Note: Check jar file paths are mapped properly in the proguard.cfg file.

Wednesday, October 24, 2012

Java : Push notifications for iOS and Android


This post gives a small idea about the push notification of iOS and Android.
Life Cycle of Push notification looks as follows




Push Notification overview of APN and GCM Server as follows

PUSH NOTIFICATION
IPhone / IPad
Android
Login into developer console
Login into Google API console,
1. Creating the SSL certificate
1.1. Generating a Certificate Request
    Launch the Keychain Access application on your Mac.
    Select the menu item Keychain Access > Certificate Assistant > Request a Certificate From a Certificate Authority…
    Enter you name and email address (leave CA Email Address blank).
    Select "Saved to disk" to download the .certSigningRequest file to your desktop.

1.2 Creating and Configuring an AppID
                Navigate to the Apple Developer Member Center website, and enter the iOS Provisioning Portal.
                Select App IDs from the menu on the left.
                Select the "New App ID" button and create a new App ID. Make sure you do not enter the wildcard character ("*") in the "Bundle Identifier" field.
                Select "Configure" beside your newly created App ID.
                Check "Enable for Apple Push Notification service". Then, Click "Configure" beside the "Development Push SSL Certificate". The "Apple Push Notification service SSL Certificate Assistant" wizard should be displayed.
                Select "Continue", then select "Choose File" and locate the .certSigningRequest file you created in the previous step.
                Select "Generate" and download the generated SSL certificate.
                Double click on the downloaded SSL certificate to install it in your Keychain.
                In your keychain, under "My Certificates", find the certificate you just added. It should be called "Apple Development IOS Push Services: xxx".
                Right-click on it, select "Export Apple…", and save it as a .p12 file. Do not enter an export password when you prompted!

2. Creating the Provisioning Profile
    Select the "Provisioning" tab in the iOS Provisioning Portal.
    Create a new profile by selecting "New Profile".
    Fill in the information. Make sure you select your developer certificate, the App ID you just created, and the devices you'll be testing with.
    Download the generated Provisioning Profile by clicking the "Download" button under the "Actions" column.
    Install the profile by double-clicking on the downloaded file. This should open the iPhone Configuration Utility App.
               
3. Configuring the Parse App
                If you want your users to be able to send push notifications, you will need to toggle the "Client push enabled?" option to "on" under the "Push Notification Settings" header. This is useful for applications like chat clients, where users need to send push messages. For this tutorial, select toggle the option to "on".
If you haven't created an API project yet, this page will prompt you to do so:
Click Create project. Your browser URL will change to something like:

Note: #project: (4815162342 in this example). This is your project ID,
To enable the GCM service:
  1. In the main Google APIs Console page, select Services.
  2. Turn the Google Cloud Messaging toggle to ON.
Use bundle identifier in the project
Use the project ID (4815162342) in the project
P12 key is generated for the above bundle identifier, Use the p12 key and respective pwd to send push notification from your server to apple server
Create new Server key, which looks like
AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx and used to send push notification from your server to GCM server


Client Side Code
// Register for push notifications

[application registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
// Register for push notifications
Handling Remote Notifications
public class GCMIntentService extends GCMBaseIntentService {
public GCMIntentService() {
                super("PRODUCT_ID");
}
// Here PRODUCT_ID is 4815162342
@Override
protected void onError(Context arg0, String arg1) {
}

@Override
protected void onMessage(Context arg0, Intent arg1) {
}

@Override
protected void onRegistered(Context arg0, String arg1) {
}

@Override
protected void onUnregistered(Context arg0, String arg1) {
}
}

for more details visit Android Guide GCM
didRegisterForRemoteNotificationsWithDeviceToken:
Tells the delegate that the application successfully registered with Apple Push Service (APS).
Device Token is generated
Length of the device token is 64 bit.
Send Device Token to server, so it can use it to send push notification
onRegistered(Context context, String regId):
Called after a registration intent is received, passes the registration ID assigned by GCM to that device/application pair as parameter. Typically, you should send the regid to your server so it can use it to send messages to this device.
Java Server Side Code
Add jar file : JavaPNS_2.2.jar
Add Jar file : gcm-server.jar

Thanks for reading :).
Whether this post is helpful? Please leave a comment.