UI Activity View Controller Showing in different language?-iOS - iphone

I am creating an app where the user can share different forms. What is weird is when I test the app on a iPhone, the Activity View controller works fine
But when I do the exact same thing on the ipad, but in a different storyboard. It does this:
Here is the code from which both of these views are getting their actions:
#import "FluteS.h"
#import "TUSafariActivity.h"
#import "ARChromeActivity.h"
#interface FluteS ()
#end
#implementation FluteS
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(IBAction)actionButton:(id)sender;{
NSLog(#"actionButton pressed");
NSBundle *bundle=[NSBundle mainBundle];
NSString *filePath = [bundle pathForResource:#"Flute" ofType: #"pdf"];
NSURL *fileURL= [NSURL URLWithString:#"http://www.friendswoodmustangband.org/wp-content/uploads/2012/04/Flute-Audition-Scales1.pdf"];
NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
NSArray *activityItems = #[fileUrl, fileURL];
ARChromeActivity *chromeActivity = [[ARChromeActivity alloc] init];
TUSafariActivity *TUSafari = [[TUSafariActivity alloc] init];
NSArray *applicationActivities = [NSArray arrayWithObjects:TUSafari,chromeActivity, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities: applicationActivities];
activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePostToWeibo];
[self presentViewController:activityVC animated:YES completion:nil];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSBundle *bundle=[NSBundle mainBundle];
NSString *filePath = [bundle pathForResource:#"Flute" ofType: #"pdf"];
NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
NSURLRequest *request = [NSURLRequest requestWithURL:fileUrl];
[_webView loadRequest:request];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I have already checked the localized part of the Info.plist, but I can't Figure out why it works on the iPhone, but not on the iPad. Does anybody have any idea what is happening?

When presenting the view controller, you must do so using the appropriate means for the current device. On iPad, you must present the view controller in a popover. On iPhone and iPod touch, you must present it modally.
You can use the following code for iPad.
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[#"something"] applicationActivities:nil];
self.popover = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
self.popover.delegate = self;
[self.popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Hope it helps you.

Related

Error when using ASIHttpRequest on viewController to UISplitviewController

I have a UISplitViewController which implements a masterNavigationController and a detailNavigationController, basic from the XCode template.
The masterNavigationController calls an other NSObject called "API" which in its turn uses ASIHTTPRequest to retrieve certain JSON data from an server.
Everything is fine and dandy, until I the call from the request starts. It shows the GUI of iPad and crashes straight after with an EXC_BAD_ACCESS. The error message I get is the following:
2012-10-10 21:13:42.357 myapp[24409:c07] Splitview controller
is expected to have a view
controller at index 0 before it's used!
I have tried different things to try to solve the issue, one of them being setting the SplitViewController delegate after settings the view controllers, an other is using the NetworkQueue instead.
This is the code of the masterNavigationController:
[...]
- (void)viewDidLoad
{
[UIHelper setNavigationBackBackground:self.navigationController.navigationBar widePage:NO];
[UIHelper setViewBackground:self.parentViewController.view widePage:NO];
[UIHelper setTableViewStyle:self.tableView];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
API *api = [[API alloc] init];
[api setDelegate:self];
[api setDidFinishSelector:#selector(didFinish:)];
[api getCommingRetrievals];
}
[...]
The AppDelegate:
[...]
MasterViewController *masterViewController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
masterViewController.detailViewController = detailViewController;
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.view.opaque = NO;
self.splitViewController.view.backgroundColor = [UIColor clearColor];
self.splitViewController.viewControllers = #[masterNavigationController, detailNavigationController];
masterViewController.managedObjectContext = self.managedObjectContext;
self.splitViewController.delegate = detailViewController;
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
[...]
This is the API object's code:
- (void)getCommingRetrievals
{
[self getRetrievalsForDate:[NSDate date]];
}
- (void)getRetrievalsForDate:(NSDate*)date
{
NSString *stringFromDate = #"";
if (date != nil)
{
// Set date string
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"yyyyMMdd"];
stringFromDate = [formatter stringFromDate:date];
}
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"%#/bookings/%#", API_BASE_DOMAIN, stringFromDate]];
[self callApi:url requestMethod:#"GET"];
}
#pragma mark -
#pragma mark API methods
- (void)callApi:(NSURL*)url requestMethod:(NSString*)requestMethod
{
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setRequestMethod:requestMethod];
[request setDelegate:self];
[request setDidFinishSelector:#selector(requestFinished:)];
[request setDidFailSelector:#selector(didFailWithError:)];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
if (self.delegate && [self.delegate respondsToSelector:didFinishSelector]) {
[self.delegate performSelector:didFinishSelector withObject:self];
}
}
If I comment out the line [request startAsynchronous];, the app doesn't crash.
What am I missing here, and how can I solve the problem?
Check that your UISplitViewController has been passed 2 view controllers.
Other than that, some idiomatic stuff:
This should go right at the beginning of any setting up stuff:
[super viewDidLoad];
e.g. `[super viewDidLoad]` convention
And consider using another framework than ASI. It's a dead library. AFNetworking, MKNetworkingKit or RESTKit are good alternatives.

Opening a pdf inside the app breaks the design

I'm having some kind of problems with one thing, i'm making an app and i have a webview that shows a pdf file, and i have a button if clicked will call an UIDocumentInteractionController (open the pdf in a new window).
I will leave screenshots to make it easier:
When i open the app:
http://imgur.com/dpIEd
After i open the UIDocumentInteractionController:
http://imgur.com/VYV2N
Here's the code too
.h file
#interface pdfView : UIViewController <UIDocumentInteractionControllerDelegate>
{
IBOutlet UIActivityIndicatorView *loading;
IBOutlet UIWebView *Wview;
UIDocumentInteractionController *controller;
}
#property (nonatomic, retain) IBOutlet UIActivityIndicatorView *loading;
#property (nonatomic, retain) IBOutlet UIWebView *Wview;
#property (nonatomic, retain) UIDocumentInteractionController *controller;
-(void)buttonPressed;
-(IBAction)open_in:(id)sender;
-(IBAction)back:(id)sender;
#end
.m file
#import "pdfView.h"
#implementation pdfView
#synthesize loading,Wview;
#synthesize controller;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)viewDidLoad
{
[loading startAnimating];
[super viewDidLoad];
Wview.scalesPageToFit = TRUE;
Wview.multipleTouchEnabled = TRUE;
[Wview setOpaque:NO];
NSString *path = [[NSBundle mainBundle] pathForResource:#"guia_seguranca_2" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[Wview loadRequest:request];
[loading stopAnimating];
}
-(IBAction)open_in:(id)sender
{
NSString *fileToOpen = [[NSBundle mainBundle] pathForResource:#"guia_seguranca_2" ofType:#"pdf"];
UIDocumentInteractionController* preview = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileToOpen]];
preview.delegate = self;
[preview presentPreviewAnimated:YES];
[preview retain];
}
-(IBAction)back:(id)sender
{
[self.view removeFromSuperview];
}
-(void)buttonPressed
{
//[self.view removeFromSuperview];
NSString *fileToOpen = [[NSBundle mainBundle] pathForResource:#"guia_seguranca_2" ofType:#"pdf"];
UIDocumentInteractionController* preview = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileToOpen]];
preview.delegate = self;
[preview presentPreviewAnimated:YES];
[preview retain];
}
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
return self;
}
- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller
{
return self.view;
}
- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller
{
return self.view.frame;
}
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
[self.controller autorelease];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc
{
[super dealloc];
[Wview release];
[loading release];
}
#end
Thanks in advance.....
I would suggest not useing the webview and using a pdf app (ibook, cloudreader) like this.
//name of pdf
NSString * pathString = #"userguide";
//get pdf path
NSString * filePath = [[NSBundle mainBundle] pathForResource:pathString ofType:#"pdf"];
NSURL *url = [NSURL fileURLWithPath:filePath];
self.docController = [UIDocumentInteractionController interactionControllerWithURL:url];
BOOL isValid = [self.docController presentOpenInMenuFromRect:self.handBookLaunch.frame inView:self.view animated:YES];
if (!isValid) {
NSString * messageString = [NSString stringWithFormat:#"No PDF reader was found on your device. Please download a PDF reader (eg. iBooks)."];
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:#"Error" message:messageString delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
Solved, added this code for layout verification:
-(void) viewWillAppear:(BOOL)animated
{
CGRect arect=[[UIScreen mainScreen]applicationFrame];
CGRect anotherrect=[[UIApplication sharedApplication]statusBarFrame];
if(self.view.center.y==arect.size.height/2)
self.view.center=CGPointMake(self.view.center.x, self.view.center.y+anotherrect.size.height); // fix silliness in IB that makes view start 20 pixels higher than it should on iPhone
}
source: https://discussions.apple.com/thread/2658315?start=0&tstart=0

QLPreviewController - not displaying image from bundle?

This is my code... i've tried every path-format I can think of to get this to work... Basically I want to show an image in a quick and easy picture viewer... The viewer shows (modally... brilliant) but then the image dosen't show inside of that... I can't think why, the image definitely exists, and yet it just shows as a black screen.
thanks for any help. :)
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
QLPreviewController *preview = [[QLPreviewController alloc] init];
[preview setDataSource:self];
[self presentModalViewController:preview animated:YES];
}
#pragma mark QLPreviewController delegate methods
- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller {
return 1;
}
- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index {
NSString *imagePath = [NSString stringWithFormat:#"%#",[[NSBundle mainBundle] bundleURL]];
NSString *nextPath = [imagePath stringByAppendingPathComponent:imageName];
NSURL *imageURL = [NSURL URLWithString:nextPath];
return imageURL;
}
NSURL *imageURL = [NSURL URLWithString:nextPath];
[NSURL fileURLWithPath:nextPath];

How to use MPMoviePlayerViewController on iOS4(3.1.3 update)

My iPhone is a iOS4(3.1.3 update).
I tryid this code.
#import <UIKit/UIKit.h>
#interface testViewController : UIViewController {
}
#end
//-------------------------------------------------
#import <MediaPlayer/MediaPlayer.h>
#import "testViewController.h"
#implementation testViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSBundle *Bundle = [NSBundle mainBundle];
NSString *moviePath = [Bundle pathForResource:#"test" ofType:#"MOV"];
NSURL *videoURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerViewController *theMovie = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[self presentMoviePlayerViewControllerAnimated:theMovie];
theMovie.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[theMovie.moviePlayer play];
}
- (void)dealloc {
[super dealloc];
}
#end
when I run the aplication the video didn't work just only plays sound.
What is wrong with this code?
Thanks.
just add below source to code:-
[themovie.view setFrame: self.view.bounds];
[self.view addSubview:themovie.view];
Then it will worked sure......

When and where are controller's properties supposed to be set?

This time, I was wondering when I was supposed to set my properties ...
I got a nav bar which I use to push a new controller (controlling a Web View) :
NewsViewController *webViewController = [[NewsViewController alloc] init]; // I create my controller
webViewController.urlText = #"http://www.google.fr"; // I set the property
InfonulAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.newsNavController pushViewController:webViewController animated:YES];
[webViewController release];
I don't know why but the code below doesn't work :
- (void)viewDidLoad { //viewDidLoad from my webViewController
[super viewDidLoad];
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlText];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
}
I just want to create a UIWebView but I need to give the controller the URL to use !
Any idea where and when my urlText property needs to be set ?!?
Cheers,
Gauthier
Do you use property correctly? Like
#property(nonatomic,retain) NSString *urlText;
If so, try to use a customized init method like this;
-(id)initWithUrl:(NSString *)url
{
if(self = [super init])
{
self.urlText = url;
}
return self;
}
dont forget to release urlText in dealloc. Now use;
NewsViewController *webViewController = [[NewsViewController alloc] initWithUrl:#"someUrl"];