iam working on a simple phonegap application in that it takes around 3 minute to load the file(for showing home page ) till that time it showing the splash image(launch screen) is there any way to make it fast???
Total "WWW" folder file size is 5.3MB
my app delegate application didFinishLaunchingWithOptions() show below
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
#if __has_feature(objc_arc)
self.window = [[UIWindow alloc] initWithFrame:screenBounds];
#else
self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
#endif
self.window.autoresizesSubviews = YES;
#if __has_feature(objc_arc)
self.viewController = [[MainViewController alloc] init];
#else
self.viewController = [[[MainViewController alloc] init] autorelease];
#endif
self.viewController.useSplashScreen = YES;
// Set your app's start page by setting the <content src='foo.html' /> tag in config.xml.
// If necessary, uncomment the line below to override it.
// self.viewController.startPage = #"index.html";
// NOTE: To customize the view's frame size (which defaults to full screen), override
// [self.viewController viewWillAppear:] in your view controller.
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
I've known other people with similar issues (but not 3 minute delays!), I'm not sure there is much you can do, I think we need to wait for the PhoneGap people to develop a system that makes it more efficient in loading.
Related
I am loading an image into an UIWebView with content mode set to aspect fit. I see there is some empty space in the bottom of the UIWebView. Is there a way to find actual image width and height after loading ? I don't see any direct API for this purpose.. I am posting the code which i tried here..
aWebView = [[UIWebView alloc]initWithFrame:mapRect];
aWebView.userInteractionEnabled = YES;
aWebView.backgroundColor = [UIColor clearColor];
aWebView.opaque = NO;
aWebView.scalesPageToFit = YES;
aWebView.delegate = self;
aWebView.scrollView.contentMode = UIViewContentModeScaleAspectFit;
aWebView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:aWebView];
NSURL *url = [NSURL URLWithString:urlText];
NSURLRequest *urlRequest = [[NSURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:120];
[aWebView loadRequest:urlRequest];
aWebView.scrollView.delegate = self;
aWebView.delegate = self;
Note: The image is loading from remote server. This is a Native iOS application that is targetted for both iOS 7 and iOS 8.
Thanks..
Here is the solution that iOS provides to find the actual size after rendering the image view in the given rectangle..
Assume origImgSize is actual physical image size and targetImgSize is the rectangular area of UIImageView on the screen..
CGRect sizeBeingScaledTo = AVMakeRectWithAspectRatioInsideRect(origImgSize, CGRectMake(0, 0, targetImgSize.width, targetImgSize.height));
This gives the actual size of the image after rendering using AspectFit mode.
I've been using the FacebookLikeView classes in a lot of apps to enable Facebook profile liking within apps. Recently the code has started crashing in every app I've put it in. The Facebook app is setup correctly and everything. This is the line it is giving an EXC_BAD_ACCESS on:
else if ([fbEvent isEqualToString:#"xfbml.render"] && [_delegate respondsToSelector:#selector(facebookLikeViewDidRender:)])
[_delegate facebookLikeViewDidRender:self];
And it's being implemented like so:
_facebook = [[Facebook alloc] initWithAppId:fbAppID andDelegate:self];
self.facebookLikeView = [[FacebookLikeView alloc]init];
[self.facebookLikeView setFrame:CGRectMake(117, 140, 82, 19)];
self.facebookLikeView.delegate = self;
self.facebookLikeView.href = [NSURL URLWithString:user];
self.facebookLikeView.layout = #"button_count";
self.facebookLikeView.showFaces = NO;
[self.facebookLikeView load];
You should set your facebookLikeView to nil in your dealloc method or viewdidunload method
I've an app builded for iOS < 6, and before it all the features work perfectly. Now I've used a switch that recognizes the iOS installed on a device and then my app opens the correct maps to get directions from the local position to another (some pins on the map). The problem is that before iOS 6, the app opens the native maps and show the route to the user. Now, If the device uses iOS 6, the app opens the Apple Maps but shows a pop-up with something like "Impossible to get direction between this 2 positions". Why? Can someone helps me to solve this problem?
Here how I pass the coordinate to maps from a disclosure button:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
[self.navigationController pushViewController:[[UIViewController alloc] init] animated:YES];
if (SYSTEM_VERSION_LESS_THAN(#"6.0")) {
NSString* addr = [NSString stringWithFormat:#"http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude];
NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
}
else {
NSString* addr = [NSString stringWithFormat:#"http://maps.apple.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude];
NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
}
Whilst you can use the URL method for maps (http://maps.apple.com/...), I've found it not to be great when presenting specific locations. Your best bet would be to use MapKit objects on iOS 6 and above.
Example:
CLLocationCoordinate2D location;
location.latitude = ...;
location.longtitude = ...;
MKPlacemark* placemark = [[MKPlacemark alloc] initWithCoordinate:location addressDictionary:nil];
MKMapItem* item = [[MKMapItem alloc] initWithPlacemark:placemark];
//... Any Item customizations
NSDictionary* mapLaunchOptions = ...;
[item openInMapsWithLaunchOptions:mapLaunchOptions];
This will open Apple Maps directly, with the item you have provided.
In order to deal with directions, use the MKLaunchOptionsDirectionsModeKey launch option, and provide the start and end map items via:
[MKMapItem openMapsWithItems:mapItems launchOptions:launchOptions];
Just to clarify the other answer, you have two options when giving directions: driving or walking. Here are the ways to do each one:
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude) addressDictionary:nil];
MKMapItem *destination = [[MKMapItem alloc] initWithPlacemark:placemark];
//This is for driving
[MKMapItem openMapsWithItems:#[destination] launchOptions:#{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving}];
//This is for walking
[MKMapItem openMapsWithItems:#[destination] launchOptions:#{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeWalking}];
More info from Apple's docs over here.
I am working on an iOS app that needs to display webpages from a server inside a UIWebView while injecting relevant local png and css files as needed in order to speed up load time. Here is the code I am using to try to do this:
NSData *myFileData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://www.example.com/index.html"]]];
NSString* myFileHtml = [[NSString alloc] initWithData:myFileData encoding:NSASCIIStringEncoding];
[myWebView loadHTMLString:myFileHtml baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
My problem is that some of the webpages have buttons in them that link to other webpages on the server, and because the UIWebView is only loading a string, the buttons when tapped don't cause the UIWebView to load the new webpage URL like it would if I had used the loadRequest method.
My question is how can I get the the UIWebView to behave like it is loading a request while still injecting local files from the baseurl?
Thanks
The relative links in the button cannot work, because the linked pages are on a remote server and not on the device's file system. However you can use a UIWebViewDelegate method to make it work:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSString *localRootPath = [NSString stringWithFormat:#"file://%#", [[NSBundle mainBundle] bundlePath]];
NSString *remoteRootPath = #"http://yourdomain.com";
NSString *remotePath = [[request.URL absoluteString] stringByReplacingOccurrencesOfString:localRootPath withString:remoteRootPath];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:remotePath]]];
// or you can use your own loading mechanism here
return NO;
}
return YES;
}
This method intercepts all requests from your WebView. If the request was triggered by a user tap / click the URL gets modified from a relative URL to a absolute URL so it can be loaded from the server. Don't forget to set the delegate on the WebView or this method will not be called.
NSURLPRotocol is a handler for NSURLConnection and will give you the opportunity to intercept the calls to the server and substitute your own content.
1) Derive a class from NSURlProtocol
2) Call NSURLProtocol registerClass: in your application:didFinishLaunchingWithOption
3) Read the documentation on implement these methods as necessary:
initWithRequest:cachedResponse:client:,
startLoading,
URLProtocol:didReceiveResponse:cacheStoragePolicy:
URLProtocolDidFinishLoading:
I'm working with ShareKit, an open-source sharing foundation for iOS apps. There is a known bug that prevents the Kit from detecting what your root view controller is. The fix for that bug is adding [SHK setRootViewController:myViewController]; in the app delegate.
If the fix is in the UIApplication didFinishLaunching method, wouldn't the view controller just be self? What am I missing? I've also tried self.viewController, self.window.rootViewController and self.window to no avail.
EDIT: Here's the entire didFinishLoading:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[Chatter_BoxViewController alloc] initWithNibName:#"Chatter_BoxViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[SHK setRootViewController:self.viewController];
return YES;
}
If it would only be "self" in the didFinishLaunching it would refer to the UIApplication, don't you agree? Are you initing correctly the viewController? Post some more code. :)
Comment to your Edit:
If you have your Window set normally in your XIB you don't need this:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
Also, if you do this (presuming your viewController is retained as property):
self.viewController = [[Chatter_BoxViewController alloc] initWithNibName:#"Chatter_BoxViewController" bundle:nil];
You will have a leak. Just do this:
viewController = [[Chatter_BoxViewController alloc] initWithNibName:#"Chatter_BoxViewController" bundle:nil];