2014-07-21 26 views
0

我正在嘗試ios的cordova項目。 我在我的日誌中獲得了一個資產url,並且在我的代碼中嘗試了這個url,它工作正常。 但是,我需要這個資產url作爲從目標C到javascript的返回值。如何在iOS Cordova項目中將資產url從目標C返回給javascript?

- (void)saveImageDataToLibrary:(CDVInvokedUrlCommand*)command{ 
    self.callbackId = command.callbackId; 
    NSData* imageData = [NSData dataFromBase64String:[command.arguments objectAtIndex:0]]; 

    UIImage* image = [[[UIImage alloc] initWithData:imageData] autorelease]; 

    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); 

    UIImage *viewImage = image; // --- mine was made from drawing context 
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 
    // Request to save the image to camera roll 
    [library writeImageToSavedPhotosAlbum:[viewImage CGImage] orientation:(ALAssetOrientation)[viewImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){ 
     if (error) { 
      NSLog(@"error"); 
     } else { 
     NSLog(@"url %@", assetURL); 
     } 
    }]; 
    [library release]; 
} 

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{ 
    // Was there an error? 
    if (error != NULL) 
    { 
     // Show error message... 
     NSLog(@"ERROR: %@",error); 
     CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString:error.description]; 
     [self.webView stringByEvaluatingJavaScriptFromString:[result toErrorCallbackString: self.callbackId]]; 
    } 
    else // No errors 
    { 
     // Show message image successfully saved 
     NSLog(@"IMAGE SAVED!"); 
     CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsString:@"Image saved"]; 
    [self.webView stringByEvaluatingJavaScriptFromString:[result toSuccessCallbackString: self.callbackId]]; 
    } 
} 

這裏.... 此代碼給我的日誌....

NSLog(@"url %@", assetURL); 

我想獲得這個assetURL我的返回值,以我的javascript,我在哪裏調用這個函數...

我已經stucked這裏一個星期...

幫我從這個...緩解

日Thnx提前.....

回答

0

謝謝大家誰已經試過這....我一些搜索後得到它.... 我說的NSLog行後添加的代碼在上面顯示的代碼中...它如下...

NSLog(@"url %@", assetURL); 
     CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsString:[assetURL absoluteString]]; 
     [self.webView stringByEvaluatingJavaScriptFromString:[result toSuccessCallbackString: self.callbackId]];