UIWebView 相应本地事件

前端之家收集整理的这篇文章主要介绍了UIWebView 相应本地事件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Objective-c代码
  1. -(BOOL)webView:(UIWebView*)webViewshouldStartLoadWithRequest:(NSURLRequest*)requestnavigationType:(UIWebViewNavigationType)navigationType{
  2. AppDelegate*appDelegate=( AppDelegate*)[[UIApplicationsharedApplication]delegate];
  3. if(navigationType==UIWebViewNavigationTypeLinkClicked){
  4. NSURL*URL=[requestURL];
  5. NSLog([URLscheme]);
  6. NSLog([URLabsoluteString]);
  7. //codehereandcallthedelegatemethod
  8. NSAutoreleasePool*pool=[[NSAutoreleasePoolalloc]init];
  9. BOOLaudioResult=FALSE;
  10. NSFileManager*fileManager=[NSFileManagerdefaultManager];
  11. //checkiffileexistedincachefolder
  12. NSArray*cache=NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES);
  13. NSString*cachePath=[cacheobjectAtIndex:0];
  14. NSString*filepath;
  15. filepath=[cachePathstringByAppendingPathComponent:[audioIdstringByAppendingString:@".wav"]];
  16. if([fileManagerfileExistsAtPath:filepath]==YES){
  17. [selfplayVoice:filepath];
  18. }
  19. else
  20. {
  21. audioResult=[appDelegatesaveAudio:audioId];
  22. if(audioResult==YES)
  23. //NSLog(@"Speaktheaudiobythepath=%@",filepath);
  24. [poolrelease];
  25. [appDelegatesaveAudio:gotFM];
  26. }


保存声音的方法
-(BOOL)saveAudio:(NSString*)key
  • NSLog(key);
  • BOOLsaveSuccess=FALSE;
  • NSString*dbPath=[[[NSBundlemainBundle]resourcePath]stringByAppendingPathComponent:@"testVoice.db"];
  • if(sqlite3_open([dbPathUTF8String],&database_voice)==sqlITE_OK)
  • NSString*sqlString=[NSStringstringWithFormat:@"select*fromtb_voicewhereid='%@'",key];
  • NSLog(sqlString);
  • constchar*sql_char=[sqlStringUTF8String];
  • //preparetheselectstatement
  • intreturnValue=sqlite3_prepare_v2(database_voice,sql_char,-1,&selectStatement,NULL);
  • if(returnValue==sqlITE_OK)
  • //loopalltherowsreturnedbythequery.
  • if(sqlite3_step(selectStatement)==sqlITE_ROW)
  • NSString*filename=[NSStringstringWithUTF8String:(char*)sqlite3_column_text(selectStatement,0)];
  • ////NSLog(filename);
  • NSData*fileData=[NSDatadataWithBytes:sqlite3_column_blob(selectStatement,0)">2)length:sqlite3_column_bytes(selectStatement,0)">2)];
  • //savethefiledata
  • //check
  • NSString*filepath=[cachePathstringByAppendingPathComponent:filename];
  • filepath=[filepathstringByAppendingString:@".wav"];
  • if([fileManagercreateDirectoryAtPath:cachePathattributes:nil]==NO){
  • ////NSLog(@"fileManagercreateDirectoryAtPath:cachePathattributes:nil");
  • if([fileDatawriteToFile:filepathatomically:YES]){
  • saveSuccess=TRUE;
  • //NSLog(@"saveSuccess");
  • ////NSLog(@"returnValue");
  • //NSLog(@"saveFail");
  • sqlite3_finalize(selectStatement);
  • returnsaveSuccess;
  • }
  • 猜你在找的Sqlite相关文章