As for the source code for the phone apps I’d take a look at either the
- Android App https://github.com/spark/android-app
- iOS App https://github.com/spark/ios-app
As for your second question: if you are using the cloud you do need an internet connection to run functions like variable(), publish(), subscribe(), etc. If you want something that talks directly to your phone app I would look into the VoodooSpark firmware (https://github.com/voodootikigod/voodoospark)