2013年7月2日 星期二

sqlite 3 自定函数方法

关键字 sqlite3_create_function

这方法 ios 应该可以接受

来自

http://www.thismuchiknow.co.uk/?p=71

使用方法

sqlite3_create_function(sqliteDatabasePtr, "distance", 4, SQLITE_UTF8, NULL, &distanceFunc, NULL, NULL);

记得先定义函数

#define DEG2RAD(degrees) (degrees * 0.01745327) // degrees * pi over 180

static void distanceFunc(sqlite3_context *context, int argc, sqlite3_value **argv){// check that we have four arguments (lat1, lon1, lat2, lon2)assert(argc == 4);// check that all four arguments are non-nullif (sqlite3_value_type(argv[0]) == SQLITE_NULL || sqlite3_value_type(argv[1]) == SQLITE_NULL || sqlite3_value_type(argv[2]) == SQLITE_NULL || sqlite3_value_type(argv[3]) == SQLITE_NULL) {sqlite3_result_null(context);return;}// get the four argument valuesdouble lat1 = sqlite3_value_double(argv[0]);double lon1 = sqlite3_value_double(argv[1]);double lat2 = sqlite3_value_double(argv[2]);double lon2 = sqlite3_value_double(argv[3]);// convert lat1 and lat2 into radians now, to avoid doing it twice belowdouble lat1rad = DEG2RAD(lat1);double lat2rad = DEG2RAD(lat2);// apply the spherical law of cosines to our latitudes and longitudes, and set the result appropriately// 6378.1 is the approximate radius of the earth in kilometressqlite3_result_double(context, acos(sin(lat1rad) * sin(lat2rad) + cos(lat1rad) * cos(lat2rad) * cos(DEG2RAD(lon2) - DEG2RAD(lon1))) * 6378.1);}

sqlite 3 自定函数

关键字 sqlite3_create_function

这方法 ios 应该可以接受

来自

http://www.thismuchiknow.co.uk/?p=71

使用方法

sqlite3_create_function(sqliteDatabasePtr, "distance", 4, SQLITE_UTF8, NULL, &distanceFunc, NULL, NULL);

记得先定义函数

#define DEG2RAD(degrees) (degrees * 0.01745327) // degrees * pi over 180

static void distanceFunc(sqlite3_context *context, int argc, sqlite3_value **argv){// check that we have four arguments (lat1, lon1, lat2, lon2)assert(argc == 4);// check that all four arguments are non-nullif (sqlite3_value_type(argv[0]) == SQLITE_NULL || sqlite3_value_type(argv[1]) == SQLITE_NULL || sqlite3_value_type(argv[2]) == SQLITE_NULL || sqlite3_value_type(argv[3]) == SQLITE_NULL) {sqlite3_result_null(context);return;}// get the four argument valuesdouble lat1 = sqlite3_value_double(argv[0]);double lon1 = sqlite3_value_double(argv[1]);double lat2 = sqlite3_value_double(argv[2]);double lon2 = sqlite3_value_double(argv[3]);// convert lat1 and lat2 into radians now, to avoid doing it twice belowdouble lat1rad = DEG2RAD(lat1);double lat2rad = DEG2RAD(lat2);// apply the spherical law of cosines to our latitudes and longitudes, and set the result appropriately// 6378.1 is the approximate radius of the earth in kilometressqlite3_result_double(context, acos(sin(lat1rad) * sin(lat2rad) + cos(lat1rad) * cos(lat2rad) * cos(DEG2RAD(lon2) - DEG2RAD(lon1))) * 6378.1);}

2013年7月1日 星期一

iOS 撷图方法

来自 http://blog.csdn.net/monsterguaishou/article/details/8512180

截取本区域(self.view):

UIGraphicsBeginImageContext(CGSizeMake(self.view.frame.size.width,self.view.frame.size.height));

  

 [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

  

 UIImage *viewImage UIGraphicsGetImageFromCurrentImageContext();

   UIGraphicsEndImageContext();   UIImageWriteToSavedPhotosAlbum(viewImagenilnilnil);

全屏截图:

UIWindow *screenWindow [[UIApplication sharedApplication] keyWindow];

   UIGraphicsBeginImageContext(screenWindow.frame.size);   [screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];   UIImage *viewImage UIGraphicsGetImageFromCurrentImageContext();

   UIGraphicsEndImageContext();   UIImageWriteToSavedPhotosAlbum(viewImagenilnilnil);

以上2种方法真机和模拟器都可以运行.在photo.app里可以看到照片

苹果最新开放的接口函数(全屏截图),已经有人试过了,不会reject:

CGImageRef UIGetScreenImage()

  

 CGImageRef img UIGetScreenImage();

   UIImagescImage=[UIImage imageWithCGImage:img];   UIImageWriteToSavedPhotosAlbum(scImagenilnilnil);

It still works,but only on-device (not in simulator) .

截图另存为指定名字:

UIWindow *screenWindow [[UIApplication sharedApplication] keyWindow];

 UIGraphicsBeginImageContext(screenWindow.frame.size);[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];UIImage *screenshot UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext()NSData *screenshotPNG UIImagePNGRepresentation(screenshot);

 NSArray *paths NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMaskYES);NSString *documentsDirectory [paths objectAtIndex:0];

 NSError *error nil;[screenshotPNG writeToFile:[documentsDirectorystringByAppendingPathComponent:@"screenshot.png"] options:NSAtomicWriteerror:&error];

部分代码来自:http://stackoverflow.com/questions/692464/emailing-full-screen-of-iphone-app

没有ipad真机截图发布app的可以用此方法做个透明按钮点,哈哈.

 

//播放截图声音NSString* path = [[NSBundle mainBundle]pathForResource:@”photoShutter” ofType:@”caf”];//NSString *path = [[NSBundlebundleWithIdentifier:@"com.apple.UIKit"] pathForResource:@”Tink”ofType:@”aiff”];SystemSoundID soundID;AudioServicesCreateSystemSoundID((CFURLRef)[NSURLfileURLWithPath:path], &soundID);AudioServicesPlaySystemSound(soundID);// we don’t dispose of the sound to keep the sound in the cache forthe next timeAudioServicesDisposeSystemSoundID(soundID);

可以用这顺带播放一下声音

在 uiwebview 事件加入调整宽度的 viewport 设定

refer: http://stackoverflow.com/questions/15826714/how-to-size-uiwebview-in-a-uimodalpresentationformsheet

在 webview 事件加入 JS,塞入 viewport 设定

不过这是处理外部网页的方法

内部网页的话,还是请后台网页人员加入 viewport 设定比较好

- (void)webViewDidFinishLoad:(UIWebView *)webView

{

NSString* js =

@"var meta = document.createElement('meta'); "

@"meta.setAttribute( 'name', 'viewport' ); "

@"meta.setAttribute( 'content', 'width = 540px, initial-scale = 1.0, user-scalable = yes' ); "

@"document.getElementsByTagName('head')[0].appendChild(meta)";

[[self webView] stringByEvaluatingJavaScriptFromString: js];

}

iOS 登入 windows doamin

复习一下什么是 windows active domain

http://www.cnblogs.com/GreenGrass/archive/2012/08/16/2642303.html

所以,Windows Doamin/Active Domain 其实是 LDAP 的一个应用

因此,找 iOS 的 windows domain 登入方法时,可以从 ladp 开始找

例如 openldap

http://stackoverflow.com/questions/929120/search-open-directory-ldap-with-objective-c