Make Better Things



I like to make better things.

How to share text and Image on WhatsApp in iOS

Sharing text and Images on WhatsApp is now possible through Open URL Scheme (deep linking).

Send Text -

NSString * msg = @"YOUR MSG";
NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",msg];
NSURL * whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    [[UIApplication sharedApplication] openURL: whatsappURL];
} else {
    // Cannot open whatsapp
}

Send Image -

– in .h file

@property (retain) UIDocumentInteractionController * documentInteractionController;

– in .m file

if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]){

    UIImage     * iconImage = [UIImage imageNamed:@"YOUR IMAGE"];
    NSString    * savePath  = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.jpg”];

    [UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];

    _documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
    _documentInteractionController.UTI = @"net.whatsapp.image";
    _documentInteractionController.delegate = self;

    [_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];

} else {
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@“No WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}

You need add these lines in .plist file for iOS 9:

<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
</array>

How to delete a folder from git history

You can follow these steps to delete a folder from git history.

#Removing folder from git history
git filter-branch --tree-filter 'rm -rf node_modules' --prune-empty HEAD
#Adding removed folder in ".gitignore" file so that we don't track it anymore
echo node_modules/ >> .gitignore
#Adding .gitignore and committing this change in repo
git add .gitignore
git commit -m 'Removing node_modules from git history'
#Now freeing up spaces from removed references
git gc
#Pushing changes to server forcefully
git push origin master --force

Clone a Git repo without history (just latest commit)

One common problem with big git repos is it takes a lot of time to clone, because in cloning git download everything beginning form the first commit. Sometimes we don’t need that much of history with code.

We can use “–depth” option in “git clone” command to specify how many commits we need. By providing an argument of “–depth 1″ to the clone command, the process will copy only the latest revision of everything in the repository.

For example -

git clone --depth 1 https://github.com/jquery/jquery.git jquery

This command only clones the HEAD of the jqueyr repository.

Note: Prior to git 1.9 we can’t use do pull or push on such repos.

How to show GPS strength value in iOS SDK

To show the signal strength of GPS we can use the properties of CLLocation like horizontalAccuracy and verticalAccuracy which indicate how accurate the device believes that location fix to be.

Here is some sample code -


if (someLocation.horizontalAccuracy < 0)
{
// No Signal
}
else if (someLocation.horizontalAccuracy > 163)
{
// Poor Signal
}
else if (someLocation.horizontalAccuracy > 48)
{
// Average Signal
}
else
{
// Full Signal
}

How to transfer Facebook app from one account to another

Recently one of my colleague had to transfer a Facebook app from his personal account to client’s Facebook account. (Some might think is it even possible!! For those yes its possible!)
I am posting steps to do this here hoping this will save someone’s time.

1. Assign a Facebook friend as an administrator.

Screen Shot 2014-06-11 at 6.54.29 pm
2. Ask him to accept the request and become an admin. (He has to add his account as a developer account, if not already a dev).

3. Now he goes to the App Dashboard and can see the app there. Can access the entire app. Good to go!!!

The primary administrator of the app can even delete the app from his account. Nothing happens to the transferred app.

A Big Thanks to Akhilesh Nair for finding this for us.