loading cached webpage in UIWebView in ios - ios6

I've a task that increasing speed of webpage loading in UIWebView. For that I'm moving to cache concept. Here I'm using ASIWebPageRequest to cache all the content of the webpage. Its doing well.But when load the cached webpage, the hyperlinks are not working(not linking with live url)?
and another one. If the webpage is cached means,its loads from cache otherwise loads from live url. How can I fix it?
Here is my code:
- (void)fetchURL:(NSURL *)url
{
[self setRequestsInProgress:[NSMutableArray array]];
[request setDelegate:nil];
[request cancel];
[self setRequest:[ASIWebPageRequest requestWithURL:url]];
[request setDidFailSelector:#selector(webPageFetchFailed:)];
[request setDidFinishSelector:#selector(webPageFetchSucceeded:)];
[request setDelegate:self];
[request setDownloadProgressDelegate:self];
[request setUrlReplacementMode:ASIReplaceExternalResourcesWithData];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request setCachePolicy:ASIOnlyLoadIfNotCachedCachePolicy];
// This is actually the most efficient way to set a download path for ASIWebPageRequest, as it writes to the cache directly
[request setDownloadDestinationPath:[[ASIDownloadCache sharedCache] pathToStoreCachedResponseDataForRequest:request]];
[[ASIDownloadCache sharedCache] setShouldRespectCacheControlHeaders:NO];
[request startAsynchronous];
}
- (void)webPageFetchFailed:(ASIHTTPRequest *)theRequest
{
NSLog(#"fetch error = %#",[theRequest error]);
}
- (void)webPageFetchSucceeded:(ASIHTTPRequest *)theRequest
{
NSURL *baseURL;
if ([request isFinished] ) {
baseURL = [NSURL fileURLWithPath:[request downloadDestinationPath]];
// // If we're using ASIReplaceExternalResourcesWithLocalURLs, we must set the baseURL to point to our locally cached file
} else {
baseURL = [request url];
}
if ([theRequest downloadDestinationPath]) {
NSString *response = [NSString stringWithContentsOfFile:[theRequest downloadDestinationPath] encoding:[theRequest responseEncoding] error:nil];
[webView loadHTMLString:response baseURL:baseURL];
} else {
[webView loadHTMLString:[theRequest responseString] baseURL:baseURL];
}
}

Change this line
[[ASIDownloadCache sharedCache] setShouldRespectCacheControlHeaders:NO];
to
[[ASIDownloadCache sharedCache] setShouldRespectCacheControlHeaders:YES];
It will work

Related

Video Streaming: Using Blob URL, -Video Seek casting 404 file not found

I am a developer/creator of a Video Streaming Service, in order to server the movies I am using
createObjectURL() (BLOB URL).
The Blob Url is created and served to the html5 video element
after the video is rendered the blob URL is revoked in order to prevent the user from accessing the private movie file, however is result of this when I try to seek through the video I get an error file not found.
Would i need to recreate the blob every time I seek the video or am I declaring my blob wrong?
async renderBlob(url){
const myPlayer = this.player.current;
var xhr = new XMLHttpRequest();
xhr.open('GET', 'movie.mp4', true);
xhr.responseType = 'blob';
xhr.onload = () => {
this.setState({src: URL.createObjectURL(xhr.response)})
myPlayer.src = this.state.src
myPlayer.play()
};
xhr.onerror = function(e) {
alert("Error " + e.target.status + " occurred while receiving the document.");
};
xhr.send();
}
after the video is playing:
URL.revokeObjectURL(this.state.src)
Short videos SEEK okay where as Longer Videos 1) to longer to load and 2 do not seek
GET blob:http://localhost:3000/e5fd2c07-3f8a-407e-815f-7b9314d9156d net::ERR_FILE_NOT_FOUND

Where can i get the IPhone 11 Skin for CN1 Simulator?

The AppStore now require an IPhone 11 (or high IPhone X) skin for their 6.5inch metadata images. Please can someone point me in the direction to it, for use in my Codenameone simulator.
I am on the latest install (CN1 v6), which has up to IPhoneX.skin in my .codenameone folder, but i would like to future proof as much as i can, so go with the 11. Thanks
We don't have an iPhone 11 skin yet although you can file an RFE on that here. But this doesn't matter for most.
Most people use tools such as these to generate the screenshots in a portable way:
https://www.appstorescreenshot.com/
https://theapplaunchpad.com/
https://screenshot-maker.appinstitute.com/app-screenshot-maker/screenshot?platform=ios
I had the same problem. I use a different approach to get one or more screenshots as required by the stores. In short, I execute the app on "Browser Stack App Live" (that has several real devices, like the required iPhone 11), using a code that programmatically send me one or more screenshots of the app, using a REST request.
Note that on Browser Stack App Live it's not possible to send e-mails, that's why I created my own REST API for screenshot uploads.
It's easy, I tested the following solution before sharing it. On a temporary VPS with Apache + PHP installed, or on your local machine if you have a public IP, create the following upload.php, remembering to update $server_url with your actual url:
<?php
header('Content-Type: application/json; charset=utf-8');
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: PUT, GET, POST");
$response = array();
$upload_dir = 'uploads/';
$server_url = 'https://www.example.com/mydir/';
if($_FILES['screenshot'])
{
$screenshot_name = $_FILES["screenshot"]["name"];
$screenshot_tmp_name = $_FILES["screenshot"]["tmp_name"];
$error = $_FILES["screenshot"]["error"];
if($error > 0){
$response = array(
"status" => "error",
"error" => true,
"message" => "Error uploading the file!"
);
}else
{
$random_name = rand(1000,1000000)."-".$screenshot_name;
$upload_name = $upload_dir.strtolower($random_name);
$upload_name = preg_replace('/\s+/', '-', $upload_name);
if(move_uploaded_file($screenshot_tmp_name , $upload_name)) {
$response = array(
"status" => "success",
"error" => false,
"message" => "File uploaded successfully",
"url" => $server_url."/".$upload_name
);
}else
{
$response = array(
"status" => "error",
"error" => true,
"message" => "Error uploading the file!"
);
}
}
}else{
$response = array(
"status" => "error",
"error" => true,
"message" => "No file was sent!"
);
}
echo json_encode($response);
?>
After that, mkdir uploads and chown the permissions of the php file and of the upload dir accordingly.
The server is ready.
On your app, add the following method (remember to change the String url value):
public static void sendMeScreenshot() {
Form form = Display.getInstance().getCurrent();
if (form != null) {
try {
Image screenshot = Image.createImage(form.getWidth(), form.getHeight());
form.paintComponent(screenshot.getGraphics(), true);
String file = FileSystemStorage.getInstance().getAppHomePath() + "/screenshot_" + System.currentTimeMillis() + ".png";
OutputStream output = FileSystemStorage.getInstance().openOutputStream(file);
ImageIO.getImageIO().save(screenshot, output, ImageIO.FORMAT_PNG, 1.0f);
String url = "https://www.example.com/mydir/upload.php";
MultipartRequest request = new MultipartRequest();
request.setUrl(url);
request.addData("screenshot", file, "multipart/form-data");
NetworkManager.getInstance().addToQueue(request);
} catch (IOException ex) {
Log.e(ex);
}
}
}
Finally, use a code like UITimer.timer(5000, false, hi, () -> sendMeScreenshot()); to get a screenshot of the Form you are interested to, after the wanted time.
Test in the Simulator, it should work. Add some logging and check the returned JSON in the Network Monitor. If it's all ok, open your app with Browser Stack App Live, selecting the wanted device (iPhone 11 in this case). You will find the screenshot (or screenshots) on the choosen upload dir of your VPS. You can download them with scp or open directly them in your browser.
This solution is useful if you don't own the required device, but keep in mind to don't keep online your upload.php to don't have security issues.

How to consume soap service in react native?

I am new in react native and wanted to consume soap service but did not get any api to do that. I have used fetch api for Rest service with json parser. Is there any api available to consume soap service and parse xml in react-native. In ios we create soap envelope and send to the server like :
NSString *soapMessage = [NSString stringWithFormat:
#"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchem\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<soap:Body>\n"
"<GetCitiesByCountry xmlns=\"http://www.webserviceX.NET\">\n"
"<CountryName>%#</CountryName>\n"
"</GetCitiesByCountry>\n"
"</soap:Body>\n"
"</soap:Envelope>\n",#"India"];
NSURL *url = [NSURL URLWithString:#"http://webservicex.com/globalweather.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest addValue: #"http://www.webserviceX.NET/GetCitiesByCountry"
forHTTPHeaderField:#"SOAPAction"];
[theRequest addValue: [NSString stringWithFormat:#"%lu",(unsigned long)[soapMessage length]]
forHTTPHeaderField:#"Content-Length"];
[theRequest setHTTPMethod:#"POST"];
[theRequest addValue: #"text/xml; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
self.responseData = [[NSMutableData alloc]init];
NSURLSession *soapSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]];
NSURLSessionDataTask *dataTask = [soapSession dataTaskWithRequest:theRequest];
[dataTask resume];
Same thing I am looking in react-native.

Failed to execute 'getImageData' due to cross-origin when loading image from Google Cloud Storage

We have image hosted on Google Cloud and get an link for it on the server-side using
new GcsAppIdentityServiceUrlSigner().getSignedUrl("GET", path))
And it looks like
https://storage.googleapis.com/<bucket>/<folder>/image.JPG?GoogleAccessId=<project>#appspot.gserviceaccount.com&Expires=1400686814&Signature=xPRKGFM01CkV9J4p0kzqMYmLGO1QJkFfoW7EaG%2FYfVcCZIgKCoflCE2E5kHlzG%2FZapjgQrkx%2BBEm%2FGmt2ZbezvW2nNm3KLuJFy%2BuaA%2BO1HNPdTtzuhU9q9yjioUYSA0fb%2BpnOaNHQVmLfLOvjj84l0QIKrCOFsnzfuMUwV7ZuVo%3D
We've configured CORS for bucket as this described in this link.
<?xml version="1.0" ?>
<CorsConfig>
<Cors>
<Origins>
<Origin>*</Origin>
</Origins>
<Methods>
<Method>GET</Method>
</Methods>
<ResponseHeaders>
<ResponseHeader>Content-Type</ResponseHeader>
</ResponseHeaders>
</Cors>
</CorsConfig>
gsutil cors set cors.xml gs://<bucket>
Then it worked for AssetLoader:
var viewport = $(".viewport"),
renderer = PIXI.autoDetectRenderer(null, null, null, true),
container = new PIXI.DisplayObjectContainer(),
stage = new PIXI.Stage(0xffffff, true);
var imageLink = "...";
var loader = new PIXI.AssetLoader([]);
loader.crossorigin = true;
var texture;
loader.onComplete = function () {
texture = PIXI.Sprite.fromImage(imageLink);
container.addChild(currentTexture);
stage.addChild(container);
viewport.append(renderer.view);
};
loader.load();
But caused an error
function createSpite() {
var canvas = $('').get(0),
ctx2D = canvas.getContext("2d");
image.onload = function () {
// ...
var imgData = ctx2D.getImageData(minX, minY, imgWidth, imgHeight); // causes an error
// ...
};
image.src = imageLink;
}
The error:
Uncaught SecurityError: Failed to execute 'getImageData' on
'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.
I am unfamiliar with PIXI, but I might expect that the ultimate cause would be that the image object's crossorigin property is not being set to "anonymous" or "use-credentials".
You could test this by trying to directly load the image in a cross-origin style on a test page. There's a good example here: https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image

How to share multiple urls to Facebook on iOS 6

Hi I'm using the facebook share sheet on SDK 3.1 and it works except when I try to share 2 urls it crashes.
NSArray* urls = [NSArray arrayWithObjects:#"http://google.com", #"http://yahoo.com", nil];
BOOL displayedNativeDialog = [FBNativeDialogs presentShareDialogModallyFrom:self
initialText: #"hellooo"
images: nil
urls: urls
handler: ^(FBNativeDialogResult result, NSError *error) {
if (error) {
NSLog(#"handler error:%#, %#", error, [error localizedDescription]);
} else {
if (result == FBNativeDialogResultSucceeded)
{
NSLog(#"handler success");
}
else
{
NSLog(#"handler user cancel");
}
}
}];
Result:
-[__NSCFConstantString isMusicStoreURL]: unrecognized selector sent to instance 0x3d23e8
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString isMusicStoreURL]: unrecognized selector sent to instance 0x3d23e8'
I believe that the NSArray of Urls it is taking is expecting NSURLs, not NSStrings. You can use the static URLWithString to get the NSURLs for the array.

Resources