`
ydbc
  • 浏览: 722868 次
  • 性别: Icon_minigender_1
  • 来自: 大连
文章分类
社区版块
存档分类
最新评论

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. {
  24. //NSLog(@"Speaktheaudiobythepath=%@",filepath);
  25. [selfplayVoice:filepath];
  26. }
  27. }
  28. [poolrelease];
  29. [appDelegatesaveAudio:gotFM];
  30. }


保存声音的方法:
Objective-c代码收藏代码
  1. -(BOOL)saveAudio:(NSString*)key
  2. {
  3. NSLog(key);
  4. BOOLsaveSuccess=FALSE;
  5. NSString*dbPath=[[[NSBundlemainBundle]resourcePath]stringByAppendingPathComponent:@"testVoice.db"];
  6. if(sqlite3_open([dbPathUTF8String],&database_voice)==SQLITE_OK)
  7. {
  8. NSString*sqlString=[NSStringstringWithFormat:@"select*fromtb_voicewhereid='%@'",key];
  9. NSLog(sqlString);
  10. constchar*sql_char=[sqlStringUTF8String];
  11. //preparetheselectstatement
  12. intreturnValue=sqlite3_prepare_v2(database_voice,sql_char,-1,&selectStatement,NULL);
  13. if(returnValue==SQLITE_OK)
  14. {
  15. //loopalltherowsreturnedbythequery.
  16. if(sqlite3_step(selectStatement)==SQLITE_ROW)
  17. {
  18. NSFileManager*fileManager=[NSFileManagerdefaultManager];
  19. NSArray*cache=NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES);
  20. NSString*cachePath=[cacheobjectAtIndex:0];
  21. NSString*filename=[NSStringstringWithUTF8String:(char*)sqlite3_column_text(selectStatement,0)];
  22. ////NSLog(filename);
  23. NSData*fileData=[NSDatadataWithBytes:sqlite3_column_blob(selectStatement,2)length:sqlite3_column_bytes(selectStatement,2)];
  24. //savethefiledata
  25. //check
  26. NSString*filepath=[cachePathstringByAppendingPathComponent:filename];
  27. filepath=[filepathstringByAppendingString:@".wav"];
  28. if([fileManagercreateDirectoryAtPath:cachePathattributes:nil]==NO){
  29. ////NSLog(@"fileManagercreateDirectoryAtPath:cachePathattributes:nil");
  30. }
  31. if([fileDatawriteToFile:filepathatomically:YES]){
  32. saveSuccess=TRUE;
  33. //NSLog(@"saveSuccess");
  34. ////NSLog(@"returnValue");
  35. }
  36. else
  37. {
  38. //NSLog(@"saveFail");
  39. }
  40. }
  41. sqlite3_finalize(selectStatement);
  42. }
  43. }
  44. returnsaveSuccess;
  45. }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics