Skip to content

Instantly share code, notes, and snippets.

View benbahrenburg's full-sized avatar

Ben Bahrenburg benbahrenburg

View GitHub Profile
@benbahrenburg
benbahrenburg / gist:1446135
Created December 8, 2011 04:43 — forked from tzmartin/gist:1372475
UIModule Error Hack
/*
* This is a hack solves the "Invalid method passed to UIModule" error
* It works by forcing Titanium to load SDK components into memory.
*
* Drop this file anywhere in your project and DON'T Ti.include() it.
* Be sure this file extension is .js.
* Clean and recompile your project.
*
* Enjoy!
* @tzmartin
@benbahrenburg
benbahrenburg / gist:1515352
Created December 23, 2011 21:04
Titanium : How to find the Private Directory
function privateDocumentsDirectory(){
Ti.API.info('We need to open a file object to get our directory info');
var testFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory);
Ti.API.info('Now we remove the Documents folder reference');
var privateDir = testFile.nativePath.replace('Documents/','');
Ti.API.info('This is our base App Directory =' + privateDir);
Ti.API.info('Now we add the Private Documents Directory');
privateDir+='Library/Private%20Documents/';
Ti.API.info('Our new path is ' + privateDir);
@benbahrenburg
benbahrenburg / gist:1531165
Created December 29, 2011 02:08
Per iOS 5 Ti 1.8 Way to find your SQLite file
function fetchDbFile(dbName){
Ti.API.info('We build the directory path to find ' + dbName + '.sql');
return Ti.Filesystem.getFile(Ti.Filesystem.applicationSupportDirectory, 'database', dbName + '.sql');
};
var myDbName = 'foo123';
Ti.API.info('We create a db to test our method')
var testDb = Ti.Database.open(myDbName);
Ti.API.info('No we get the file')
var dbFile = fetchDbFile(myDbName);
@benbahrenburg
benbahrenburg / app.js
Created January 5, 2012 03:04
Android 1.8.0.1 custom property tableview issue
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
// create tab group
var tabGroup = Titanium.UI.createTabGroup();
//
// create base UI tab and root window
//
@benbahrenburg
benbahrenburg / app.js
Created January 6, 2012 13:56
1.8.0.1 & CI Build Android Menu Issue
// This is a test case showing how the Android menu
// no longer works as excepted when using a function return
// similar to how you would return a window from a commonJS module
//
// To cover all test cases please update the
// useApproach variable with a number between 1 and 4
// This will return each of the examples as outlined
// in another Jira ticket located here http://jira.appcelerator.org/browse/TIMOB-6648
//
@benbahrenburg
benbahrenburg / gist:1672333
Created January 24, 2012 20:21
CommonJS Tabgroup Sample
exports.AppTabGroup = function() {
//Thanks Kevin Whinnery for the sample
//https://github.com/appcelerator-developer-relations/Forging-Titanium/blob/master/ep-006
var instance = Ti.UI.createTabGroup();
//loop through tab objects and add them to the tab group
for (var i = 0, l = arguments.length; i < l; i++) {
var tab = Ti.UI.createTab(arguments[i]);
//on initialization, we track the current tab as the first one added
if (i === 0) {
@benbahrenburg
benbahrenburg / Sample 2
Created January 30, 2012 01:02
Referencing the bencoding.network module
Ti.API.info("Create a new Carrier Info Object");
var carrierInfo = benCodingNetwork.createCarrierInfo();
Ti.API.info("Get carrier name => " + carrierInfo.carrierName);
Ti.API.info("Get mobile country code => " + carrierInfo.mobileCountryCode);
Ti.API.info("Get mobile network code => " + carrierInfo.mobileNetworkCode);
Ti.API.info("Get ISO country code for cellular service provider => " + carrierInfo.isoCountryCode);
Ti.API.info("Mobile service provider supports VOIP => " + carrierInfo.allowsVOIP);
@benbahrenburg
benbahrenburg / app.js
Created January 30, 2012 16:05
backgroundGradient Error
//Setup our app namespace
var my={};
//Bring in our helpers
my.helpers=require('helpers');
//Bring in our custom UI elements
my.uiHelpers=require('ui_helper');
//Bring in our fake modules
my.mod=require('some_mod');
//Let's get a window
my.win=my.mod.fetchWindow();
@benbahrenburg
benbahrenburg / app.js
Created February 18, 2012 18:07
Network Helpers Debug
var test2 = require('test').netTest();
@benbahrenburg
benbahrenburg / GeolocationModule.mm
Created March 11, 2012 01:41 — forked from stevenou/GeolocationModule.mm
Geofencing in Titanium
// this file located in /Library/Application Support/Titanium/mobilesdk/osx/{version_number}
// add the following methods to GeolocationModule.mm
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
NSDictionary *event = [NSDictionary dictionaryWithObjectsAndKeys:NUMBOOL(YES),@"success",[NSDictionary dictionaryWithObjectsAndKeys:NUMDOUBLE(region.center.latitude),@"lat",NUMDOUBLE(region.center.longitude),@"lng",NUMDOUBLE(region.radius),@"radius",region.identifier,@"identifier",nil],@"region",nil];
if ([self _hasListeners:@"enteredRegion"])
{
[self fireEvent:@"enteredRegion" withObject:event];