3

我正在创建一个应用程序,用户可以在其中共享不同的表单。奇怪的是,当我在 iPhone 上测试应用程序时,Activity View 控制器工作正常在此处输入图像描述

但是当我在 ipad 上做完全相同的事情时,但在不同的故事板上。它这样做:

在此处输入图像描述

以下是这两个视图获取操作的代码:

#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

我已经检查了 Info.plist 的本地化部分,但我无法弄清楚为什么它可以在 iPhone 上运行,但在 iPad 上却不行。有人知道发生了什么吗?

4

1 回答 1

1

在呈现视图控制器时,您必须使用当前设备的适当方式来执行此操作。在 iPad 上,您必须在弹出窗口中显示视图控制器。在 iPhone 和 iPod touch 上,您必须以模态方式呈现。

您可以将以下代码用于 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];

希望它可以帮助你。

于 2013-04-10T11:35:52.140 回答