Saturday, December 15, 2018

Query your MongoDB

Hey All,

Welcome back to the second phase of the MongoDB. The query part. We will run the queries on the Mongo shell.



Tips to avoid Appstore Rejection

Hey Folks,

Submission of the iOS apps to the Appstore is a tricky process. If you are planning for submission it would be great if you follow some basic guidelines provided by Apple Apple-Review-Guidelines

Here you find a list of Do's and Dont's that can help you pass the submission process with the flying colors. So here you go :P


Do's

  • Project
    • App Icon [must not contain rounded corners or layers].
    • Launch / Splash images must be added in project.
    • Bundle Identifier.
    • Production Certificates & Provisioning profile.
  • iTunes Connect
    • Set App Name.
    • Set App Icon [must not contain rounded corners or layers].
    • Provide proper description.
    • Provide screen shots of the screen of every device supported.
    • Add valid comma separated keywords.
    • Support URL is also a must so that apple or customer can reach you.
    • Detailed data in App review Information.



Dont's

  • Too less or irrelevant information under App Review Information Section has high risk of rejection. Do ensure that the credentials for login are valid and server is live/reachable.
  • Never ever use any other platform related information like Android or Windows in any of your files. Any such keyword in any file is not accepted.
  • Don't use BETA / TRIAL or TEST keywords too. Apple in any case should not sense that your app is incomplete or under trial. If you wish to test your beta app use Testflight but avoid submission.
  • Inappropriate or filthy content act as a bait for rejection.
  • Complex UI or in-usability of apps too lead to rejection.
  • Screenshots or description that are irrelevant.


Will add more data in list with time. Happy Submission :)






Thursday, November 22, 2018

SHA Encryption in IOS

Hi All,

Encryption has always been a key feature in apps developed in any Platform. Used widely in iOS Apps.

So lets today explore the SHA algorithm for encryption and decryption.


What is it

The algorithm is named as Secure Hash Algorithm. Highly used for Digital Signatures. This algorithm generates a unique and non-reversible text. Suppose if you are able to get the secret key used for hashing then alone with that you cannot generate the actual data making it secure. Also, two different kinds of data with the same secret hash code cannot generate the same hashed string.

However, with SHA1 two different strings with the same hash code generated the same hashed result resulting in a collision which led the users to move to SHA256 for better security. The larger is the bit size of hash the larger is the combination option and higher is the security but definitely, the implementation is important too.

But will longer hash length have any impact on performance? Yes, it may.


It can be broken down as

SHA[Number] [Output Size in Bits]

  • SHA0 [160]
  • SHA1 [160]
  • SHA2 [SHA224, SHA256, SHA384, SHA512]
  • SHA3 [SHA224, SHA256, SHA384, SHA512]





Plain Text >> Hash Algorithm >> Hashed Text



Utilize the Encryption logic in iOS App

1. Add Security Framework




2. Import CommonCrypto.h




Objective C

- (NSData *)hmacForKeyAndData:(NSString *)key data:(NSString *)data
{
    unsigned char cHMAC[CC_SHA1_DIGEST_LENGTH];

    const char *cKey  = [key cStringUsingEncoding:NSASCIIStringEncoding];
    const char *cData = [data cStringUsingEncoding:NSASCIIStringEncoding];

    CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC);

    return [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)];

}


Swift

func hmac(forKeyAndData key: String?, data: String?) -> Data
{
    let cHMAC = [UInt8](repeating: 0, count: CC_SHA1_DIGEST_LENGTH)

    let cKey = Int8(key?.cString(using: String.Encoding.ascii.rawValue) ?? 0)
    let cData = Int8(data?.cString(using: String.Encoding.ascii.rawValue) ?? 0)

    CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC) 

    return Data(bytes: &cHMAC, length: MemoryLayout<cHMAC>.size)
}

Thursday, November 1, 2018

Know your MongoDB

Hi All,

From past many weeks I had this eagerness to know what MongoDB is? & how it actually works. Brainstorming and learning lead to an inference that configuration is simple & easy, just follow some steps and start your journey in the new world.

So follow the trail to know what it actually is...


What is Mongo DB
A document based Database that stores Data in JSON Format. The fields can vary from document to document & YES its FREE and OPEN SOURCE.


Pros

  • Dynamic : There is no defined schema so your collection and its document can be of user's choice,  style & need.
  • No Joins required that makes it simple and easy to use
  • Flexible : Fields addition, updation is super easy and has less/no impact on he Application
  • Easy Integration & Configuration
  • It is document based & highly powerful
  • Cloud storage and distribution is key feature
  • High performance


Cons

  • Not perfectly ACID compliant
  • No stored procedure.
  • No auto-increment default option however can be achieved using Javascript code logic


Configuration

  • Download from https://www.mongodb.com/download-center
  • Alternative way to install using Homebrew as $ brew install mongodb 
  • You can configure  on local as well as remote machine
  • From 3.6 version of mongodb both mongod and mongos binaries are by default bind to LocalHost
  • Open your terminal
  • Unzip the downloaded TAR in a folder named Mongo
    • $ cd Mongo
    • $ tar-zxvf mongodb-osx-ssl-x86_64-4.0.3.tgz
  • Move
    • $ sudo mv mongodb-osx-ssl-x86_64-4.0.3 /usr/local/mongodb
  • Create a folder where Mongodb can store/write data, by default location is /data/db which needs to be created manually with proper permissions
    • $ sudo mkdir -p /data/db
    • $ sudo chown [LOGGED_IN_USER] /data/db
    • The default location can also be changed using 
      • $ mongod --dbpath /your_directory
  • To access mongodb commands you have to create a ~/.bash_profile file & assign /usr/local/mongodb/bin to $PATH environment variable
    • $ cd ~
    • $ pwd /users/[LOGGED_IN_USER]
    • $ touch .bash_profile
    • $ open .bash_profile 
      • Above command opens a text editor, paste below 2 commands in there and save
      • export MONGO_PATH=/usr/local/mongodb
      • export PATH=$PATH:$MONGO_PATH/bin
  • Restart the terminal 
  • $ mongo -version
  • $ mongod 
    • above command start the mongo daemon
  • Open another terminal window
    • $ mongo
  • Now in this terminal window you will see 
      MongoDB server version: 4.0.3
      Welcome to the MongoDB shell



What is Mongo

  • This is a JS shell interface for MongoDB which access the database


What is MongoD

  • This is a daemon, a host process for the database which runs mongodb process in background.
  • This has several default params associated with it
    • It runs on port 27017
    • Stores data in /data/db

What is bash profile & its usage in MongoDB
  • Its a hidden file that loads before the Terminal loads the shell environment
  • It contains shell configurations and preferences.
  • MongoDB paths are set in this file


Difference between SQL and Mongodb


Sql ServerMongoDB
DatabaseDatabase
TableCollection
IndexIndex
RowDocument
ColumnField
JoinsLink
PartitionRange Partition


Monday, September 24, 2018

The Savior Commands of Hg : Mercurial

Hi all,


I am back after a long time. Many of you have been using HG / Mercurial for repository work. So here goes the list of commands that I find useful and handy:

[ui]
username = swati <swati.srivastava@gmail.com>

$ hg clone <repo url> 
-- Clone from a URL


$ hg st
-- Get the status/list of all uncommitted changes


$ hg st -a
-- Get the status/list of all added files


$ hg st -m
-- Get the status/list of all modified files


$ hg st -r
-- Get the status/list of all removed files


$ hg heads
-- Get the list of all heads



$ hg tip

-- Get the latest revision of the current branch


$ hg addremove
-- Adds new files and removes the deleted files from your file system


$ hg commit -m "commit message"
-- Commit the data/files with a message


$ hg pull
-- Fetches all the code/files committed by other on all branches



$ hg update
-- Updates the working copy with the latest code


$ hg update tip
-- Updates the working copy with the latest code of the tip


$ hg update -r <revision no>
-- Updates the working copy with the latest code of the revision no mentioned


$ hg push
-- Push your committed code


$ hg push -r <revision no>
-- Push your committed code of a particular version


$ hg merge
-- Merge the code


$ hg revert
-- Undo / Discard all the uncommitted changes


$ hg strip <changeset>
-- Srips / removes the particular changeset. This may lead to error
hg : unknown command named strip
'strip' is provided by the following extension mq : manage stack of patches

Solution: open .hgrc file and write
[extensions]
mq = 



$ hg rollback
-- Rollbacks an accidental commit


$ hg diff -r<revision 1> -r<revision 2>
-- Provides difference between 2 revisions


$ hg help
-- Get a help on all types of available commands






Monday, April 9, 2018

Sensors in iPhones

Hi All,

Today I would like to share info about various sensors used in iPhones. The list may increase with time.

So here we go..

Accelerometer: Measures force of acceleration caused by any movement
  • Informs about the device Orientation.
  • Captures all the values of X, Y, Z axis.
  • Used in Gaming.
  • Available from iPhone 2G.


Gyroscope: Captures earth gravity to calculate the orientation
  • Informs about rate and angle of Rotation.
  • Used in Virtual reality.
  • Used in 360-degree rotation of images and videos.
  • Available from iPhone 4.


Finger Print Sensor: Using a capacitive touch to capture User's Finger Print

  • The Users finger can be oriented in any direction and it will be able to read.
  • Used for secure login.
  • Available from iPhone 5S.


Proximity Sensor: Detects how close is the screen to the user's body
  • Used to informs device that phone is held near ears for calling purpose so turn off the light.
  • Used to avoid accidental touch on screens.
  • Available from iPhone 2G.


BarometerCaptures altitude and elevation changes
  • Measures air pressure and temperature.
  • Used in Weather App.
  • Available from iPhone 6.


Magnetometer: Captures strength of the magnetic around the device
  • Used in Compass.
  • Available from iPhone 3GS.


Ambient Light Sensor: Adjusts the brightness of the screen depending on the amount of light its exposed to
  • Used to Conserve battery.
  • Used to avoid harmful effects of light on eyes.
  • Available from iPhone 2G.

Hope its helpful!!!

Thursday, August 24, 2017

NWJS & Mac App : Signing and Submission to Store

Hi Guys,

I am feeling very relieved and relaxed today. Wanna know WHY???

Finally I am able to sign the nwjs mac app with App store 3rd Party App and Installer certificates and create the package and yippie its on App store. :) :) :)

Lets proceed towards the starting point and follow a path to Successful upload. Here you go.


Pre-requisites for Mac App Store Upload:
  • All Apps must have Sandbox enabled. Yes its mandatory.
  • Bit Code is not supported in Mac Apps. So chill.
  • App must be packaged and submitted using Apple's packaging technology included in xcode or via command line tools.Third party installers are not allowed.
  • Bundle Display name, identifier must be properly set.
  • Provide proper Icon Files.

Mac App Certificates and their Naming Conventions:
  • The name begins with:
    • “Mac Developer” for a Mac Development certificate.
    • “3rd Party Mac Developer Application” for a Mac Submission certificate.
    • “3rd Party Mac Developer Application” for a Mac Submission certificate.
    • “3rd Party Mac Developer Application” for a Mac Submission certificate
  • Both your distribution and developer certificates appear in the My Certificates category in Keychain Access. 
    • The distribution certificates begin with the text “3rd Party Mac Developer” followed by the type of certificate and your team name.
  • Only a team agent or admin can obtain and use Distribution certificates or Developer ID certificates.


Things to Do:

  • In Info.plist of your App 
    • Add a key [if not present] named Application Category and choose its value from list provided.
    • Delete key CFBundleDocumentTypes and its Values

  • Ensure that all the files can be read by Non root users. for this you can run command in terminal
    • $ cd path_to_nwjs.app
    • $ chmod a+rX *
    • $ chmod -R u+rwX,go+rX,go-w *
    • Provide readable permission to app file , Parent and Child plists also that will be served as entitlements while code signing the app.

  • Create Parent and Child Entitlements.





  • Set the Bundle identifier of the NWJS Helper App.

  • Set the Bundle Identifier of the App_mode_loader App.

  • Now Sign the App and create package to be uploaded:
    • $ codesign -f --deep -s "3rd Party Mac Developer Application : Organization_Name (Team ID)" --entitlements Child.plist hello.app/Contents/Version/59.0.3071.115/nwjs\ Framework.framework/Resources/app_mode_loader.app
    • $ codesign -f --deep -s "3rd Party Mac Developer Application : Organization_Name (Team ID)" --entitlements Child.plist hello.app/Contents/Version/59.0.3071.115/nwjs\ Framework.framework/Versions/A/Helpers/crashpad_handler
    • $ codesign -f --deep -s "3rd Party Mac Developer Application : Organization_Name (Team ID)" --entitlements Child.plist hello.app/Contents/Version/59.0.3071.115/nwjs\ Framework.framework/Versions/A/XPCServices/AlertNotificationService.xpc/Contents/MacOS/AlertNotificationService
    • $ codesign -f --deep -s "3rd Party Mac Developer Application : Organization_Name (Team ID)" --entitlements Child.plist hello.app/Contents/Version/59.0.3071.115/nwjs\ Framework.framework/libnode.dylib
    • $ codesign -f --deep -s "3rd Party Mac Developer Application : Organization_Name (Team ID)" --entitlements Child.plist hello.app/Contents/Version/59.0.3071.115/nwjs\ Framework.framework/libffmpeg.dylib
    • $ codesign -f --deep -s "3rd Party Mac Developer Application : Organization_Name (Team ID)" --entitlements Child.plist hello.app/Contents/Version/59.0.3071.115/nwjs\ Framework.framework
    • $ codesign -f --deep -s "3rd Party Mac Developer Application : Organization_Name (Team ID)" --entitlements Child.plist hello.app/Contents/Version/59.0.3071.115/nwjs\ Framework.framework/Versions/A/nwjs\ Framework
    • $ codesign -f --deep -s "3rd Party Mac Developer Application : Organization_Name (Team ID)" --entitlements Child.plist hello.app/Contents/Version/59.0.3071.115/nwjs\ Helper.app
    • $ codesign -f --deep -s "3rd Party Mac Developer Application : Organization_Name (Team ID)" --entitlements Parent.plist hello.app

  • Create Package:
    • $ Productbuild --component "hello.app" /Applications --sign "3rd Party Mac Developer Installer : Organization_Name (Team ID)" --product "hello.app/Contents/Info.plist" myPackage.pkg

  • Upload this package using Application Loader. Choose the latest one.

You may also face some Errors:

  • The Session status is failed and the error description is "failed to open ssh session. (16)"
    • Open Preferences of Application Loader.
    • Click Advanced
    • Select only DAV and unselect Signiant and Aspera.
  • Resource fork : Finder information or similar ditritus not allowed
    • $ xattr -cr hello.app
  • Malformed framework : Framework must contain symbolic link
    • Choose nwjs version that already has inbuilt support for symlinks.
  • Unsealed contents present in the root directory of an embedded framework.
    • Do not change Info.plist files other that nwjs , nwjs Helper and app_mode_loader.app

Fix the issues and upload again.
Success is here....


Hope you guys find it useful.
Thanks a lot for the view.


:)
:)