I am trying to load html page on a web view and i am having issue with scrolling the page.I tried to add javascript with overflow changed to scroll and no luck.What am i missing here?
-(WKWebView*) getWebViewForUrl:(NSString*)relativeUrl {
WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 2, self.bounds.size.width-10, HEIGHT_WEBVIEW)];
webView.scrollView.scrollEnabled = TRUE;
webView.contentMode = UIViewContentModeScaleAspectFit;
webView.scrollView.bounces = NO;
webView.navigationDelegate = self;
NSString* endpoint = [NSUserDefaultsManager getObjectFromUserDeafults:PORTAL_ENDPOINT];
// NSString* url = [NSString stringWithFormat:#"%#/%#",endpoint,defect.html_description_source];
//NSString* url = #"http://www.yahoo.com";
NSString *url = [NSString stringWithFormat:#"%#%#.html?auth_token=%#&device_id=%#", endpoint, relativeUrl, [[NSUserDefaults standardUserDefaults] objectForKey:#"accessToken"], [DeviceManager getDeviceID]];
NSLog(#"the html %#",url);
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
return webView;
}
- (void)webViewDidFinishLoad:(WKWebView *)webView {
NSString *jsString = #"document.querySelectorAll('*[style]').forEach(el => el.style.overflow = 'scroll');";
[webView evaluateJavaScript:jsString completionHandler:nil];
[self hideLoadingScreen];
}
Related
i have tried this code but it shows error like
Warning: Attempt to present <_UIDocumentActivityViewController:
0x16acdc00> on which is already
presenting <_UIDocumentActivityViewController: 0x16ae4800>
how to solve this??
-(IBAction)saveToInstagram:(id)sender {
CGRect rect = CGRectMake(0 ,0 , 0, 0);
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents/Test.ig"];
NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:#"file://%#", jpgPath]];
NSLog(#"JPG path %#", jpgPath);
NSLog(#"URL Path %#", igImageHookFile);
self.docFile.UTI = #"com.instagram.photo";
self.docFile = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.docFile=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
[self.docFile presentOpenInMenuFromRect: rect inView: self.view animated: YES ];
NSURL *instagramURL = [NSURL URLWithString:#"instagram://media?id=MEDIA_ID"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[self.docFile presentOpenInMenuFromRect: rect inView: self.view animated: YES ];
}
else {
NSLog(#"No Instagram Found");
}
}
- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
interactionController.delegate = interactionDelegate;
return interactionController;
}
- (void)documentInteractionControllerWillPresentOpenInMenu:(UIDocumentInteractionController *)controller {
}
The problem is that while the first docfile is being presented you try to present the second one
// First presentation
[self.docFile presentOpenInMenuFromRect: rect inView: self.view animated: YES ];
NSURL *instagramURL = [NSURL URLWithString:#"instagram://media?id=MEDIA_ID"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
// Second presentation
[self.docFile presentOpenInMenuFromRect: rect inView: self.view animated: YES ];
}
I don't really understand why do you need to use the same method twice, but if you really do, then for the first presentation use animated: NO. I would suggest some kind of completion code block, but it appears that there is no such method for UIDocumentInteractionController
Don't forget to add instagram in you plist array with key: LSApplicationQueriesSchemes.
#property (nonatomic, strong) UIDocumentInteractionController *docIC;
- (void)sharePhoto:(UIImage *)image caption:(NSString *)caption
{
NSURL *instagramURL = [NSURL URLWithString:#"instagram://"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
{
NSString *imgPath = [TUtil documentPath:#"Image.igo"];
NSData *data = UIImageJPEGRepresentation(image, 1.0);
[data writeToFile:imgPath atomically:YES];
NSURL *igImageHookFile = [NSURL fileURLWithPath:imgPath];
self.docIC = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
[self.docIC setDelegate:self];
[self.docIC setUTI:#"com.instagram.exclusivegram"];
// Subject
[self.docIC setName:[[NSBundle mainBundle] objectForInfoDictionaryKey:#"CFBundleDisplayName"]];
//http://developers.instagram.com/post/125972775561/removing-pre-filled-captions-from-mobile-sharing
//self.docIC.annotation = [NSDictionary dictionaryWithObjectsAndKeys:caption, #"InstagramCaption", nil];
[self.docIC presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}
else
{
NSString *iTunesLink = #"itms-apps://itunes.apple.com/app/id389801252?mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
}
}
I am building an app that allows the opening of a PDF, and handles this like so:
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url sourceApplication:(NSString *)source annotation:(id)annotation
{
if (url != nil && [url isFileURL])
{
if ([[url pathExtension] isEqualToString:#"pdf"])
{
FilePreviewViewController *filePreviewController = [[FilePreviewViewController alloc] init];
[filePreviewController setURL:url];
[self.navController pushViewController:filePreviewController animated:NO];
return YES;
}
}
return NO;
}
And then in FilePreviewController.m:
-(void) setURL:(NSURL *) URL
{
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];
[self.documentInteractionController setDelegate:self];
[self.documentInteractionController presentPreviewAnimated:NO];
}
However, when I open a file and the view transitions, I get these messages:
Unbalanced calls to begin/end appearance transitions for <QLRemotePreviewContentController: 0x1581fe00>.
Couldn't issue file extension for path: /private/var/mobile/Containers/Data/Application/6399D00B-47A1-4F33-B34C-3F0B07B648AE/Documents/Inbox/pdf-8.pdf
And the file itself does not load. I'm not sure what I'm doing wrong because this works fine on the simulator (i.e. the PDF loads and displays perfectly).
use this code to view/read pdf format file.
.h
<UIDocumentInteractionControllerDelegate>
UIDocumentInteractionController *controller;
.m
NSString *File_name=[NSString stringWithFormat:#"%#",URL];
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *pngFilePath = [NSString stringWithFormat:#"%#/%#",docDir,[File_name lastPathComponent]];
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:URL];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
if (pdfData) {
[pdfData writeToFile:pngFilePath atomically:YES];
controller = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:pngFilePath]];
controller.delegate = self;
CGRect rect = CGRectMake(0, 0, appDelegate.wVal, appDelegate.hVal);
[controller presentOptionsMenuFromRect:rect inView:self.view animated:YES];
}
});
});
I am trying to stream a video uploaded on filepicker, but it keeps loading without playing the video.
The link is: https://www.filepicker.io/api/file/fLayj5bYTWuso1TVNknv
The page is a video/mp4 page, but as you can see there is no extension for the page.
The Code:
#interface RTVideo()
#property (nonatomic,strong) MPMoviePlayerController *moviePlayer;
#end
#implementation RTVideo
UIView *frame;
-(void)play
{
NSNumber *adId = 5 ;
NSString *session = [[NSUserDefaults standardUserDefaults]stringForKey:#"sessionID"];
NSString *type = #"video";
[NetworkManagerCenter retrievePageWithtype:type
Id:adId
session:session
success:^(RT *ad) {
[self playAD];
} failure:^(NSError *error) {
[self removeFromSuperview];
}];
}
-(void)playAD
{
frame = self;
NSURL *movieURL = [NSURL URLWithString: #"https://www.filepicker.io/api/file/fLayj5bYTWuso1TVNknv"];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[frame addSubview:self.moviePlayer.view];
self.moviePlayer.fullscreen = YES;
self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
self.moviePlayer.initialPlaybackTime = -1.0;
[self.moviePlayer prepareToPlay];
[self.moviePlayer play];
}
#end
Is this not working because there is no extension and how can I solve this?
Here is my code:
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType; {
/* Add Content Loading Banner */
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
[self.view addSubview:linkLoadView];
linkLoadView.alpha = 1.0;
}
/* Handle PDF Opening */
NSURL *url = [request URL];
NSString *urlString = [url absoluteString];
if([urlString rangeOfString:#".pdf"].location == NSNotFound){
return true;
} else {
NSURL *filePath = [NSURL URLWithString:urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:filePath];
[pdfViewer loadRequest:requestObj];
[self.view addSubview:topView];
[self.view addSubview:linkLoadView];
return false;
}
}
Basically what this does is detect a PDF link from within my UIWebView webView and loads it into an additional UIWebView pdfViewer (found on a View called topView). I then have a function as below:
- (void) webViewDidFinishLoad:(UIWebView *)theWebView{
//for webView
[UIView animateWithDuration:2
animations:^{
loadingView.alpha = 0.0;
linkLoadView.alpha = 0.0;
}
completion:^(BOOL finished){
[loadingView removeFromSuperview];
[linkLoadView removeFromSuperview];
}];
}
The above function doesn't fire at all for the pdfViewer web view, but does for the webView web view. How do I fix this?
Here is my setup settings for both webViews, on the viewDidLoad method.
//Options for
webView.delegate = self;
webView.scalesPageToFit = YES;
for (id subview in webView.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
//Options for
pdfViewer.delegate = self;
pdfViewer.scalesPageToFit = YES;
for (id subview in pdfViewer.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
Make sure that the pdfViewer delegate is set properly and you will probably need to adjust the loading code.
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType; {
/* Add Content Loading Banner */
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
[self.view addSubview:linkLoadView];
linkLoadView.alpha = 1.0;
}
/* Handle PDF Opening */
NSURL *url = [request URL];
NSString *urlString = [url absoluteString];
if(webview != pdfViewer)
{
if([urlString rangeOfString:#".pdf"].location == NSNotFound){
return true;
}
else {
NSURL *filePath = [NSURL URLWithString:urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:filePath];
[pdfViewer loadRequest:requestObj];
[self.view addSubview:topView];
[self.view addSubview:linkLoadView];
return false;
}
}
return true;
}
I would like to have both movies playing at once in their two separate sub views. They are both accessing different media.
this is on an ipad with a superview and two little views 320x240 right by eachother on the xib.
-(IBAction)playLeft:(id)sender{
if ([self.playerRight playbackState] == MPMoviePlaybackStatePlaying);
[self.playerRight stop];
[self.playerLeft play];
}
-(IBAction)playRight:(id)sender{
if ([self.playerLeft playbackState] == MPMoviePlaybackStatePlaying);
[self.playerLeft stop];
[self.playerRight play];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
self.playerLeft = [[MPMoviePlayerController alloc] init];
self.playerLeft.contentURL = [self movieURL];
NSLog(#"self.playerLeft %#", self.playerLeft);
self.playerRight = [[MPMoviePlayerController alloc] init];
self.playerRight.contentURL = [self movieURL2];
NSLog(#"self.playerRight %#", self.playerRight);
// START_HIGHLIGHT
self.playerLeft.view.frame = self.leftView.bounds;
self.playerLeft.view.autoresizingMask =
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
self.playerRight.view.frame = self.rightView.bounds;
self.playerRight.view.autoresizingMask =
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
[self.rightView addSubview:playerRight.view];
[self.leftView addSubview:playerLeft.view];
//[self.playerRight play];
//[self.playerLeft play];
//[self clickedOpenMovie:nil];
}
-(NSURL *)movieURL
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath =
[bundle
pathForResource:#"720p5994-prores-hq_iPhone_320x240 two"
ofType:#"m4v"];
//NSString *moviePath = [NSString stringWithFormat:#"http://localhost:1935/live/aStream/playlist.m3u8"];
if (moviePath) {
return [NSURL fileURLWithPath:moviePath];
//return [NSURL URLWithString:moviePath];
} else {
return nil;
}
}
-(NSURL *)movieURL2
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath =
[bundle
pathForResource:#"720p5994-prores-hq_iPhone_320x240"
ofType:#"m4v"];
if (moviePath) {
return [NSURL fileURLWithPath:moviePath];
} else {
return nil;
}
}
so the problem is that somewhere in the background MPMoviePlayerController responds to notifications and turns itself off if another MPMoviewPlayerController broadcasts that its going to start. Thus one can not have multiple MPMoviePlayerControllers playing at the same time.
you can see this by printing out the MPMoviePlayerPlaybackStateDidChangeNotification