- -(BOOL)webView:(UIWebView*)webViewshouldStartLoadWithRequest:(NSURLRequest*)requestnavigationType:(UIWebViewNavigationType)navigationType{
- AppDelegate*appDelegate=( AppDelegate*)[[UIApplicationsharedApplication]delegate];
- if(navigationType==UIWebViewNavigationTypeLinkClicked){
- NSURL*URL=[requestURL];
- NSLog([URLscheme]);
- NSLog([URLabsoluteString]);
- //codehereandcallthedelegatemethod
- NSAutoreleasePool*pool=[[NSAutoreleasePoolalloc]init];
- BOOLaudioResult=FALSE;
- NSFileManager*fileManager=[NSFileManagerdefaultManager];
- //checkiffileexistedincachefolder
- NSArray*cache=NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES);
- NSString*cachePath=[cacheobjectAtIndex:0];
- NSString*filepath;
- filepath=[cachePathstringByAppendingPathComponent:[audioIdstringByAppendingString:@".wav"]];
- if([fileManagerfileExistsAtPath:filepath]==YES){
- [selfplayVoice:filepath];
- }
- else
- {
- audioResult=[appDelegatesaveAudio:audioId];
- if(audioResult==YES)
- //NSLog(@"Speaktheaudiobythepath=%@",filepath);
- [poolrelease];
- [appDelegatesaveAudio:gotFM];
- }
保存声音的方法:
-(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;
}