在Objective c中添加UIActivityViewController最顶层的窗口

时间:2016-05-26 10:09:47

标签: ios objective-c uiactivityviewcontroller

如何将UIActivityViewController添加到最顶层窗口。

   describe('Settings Service', () => {

    beforeEach(() => {
        settingsService = new SettingsService(); // This gives a error beceause it runs the promise 
        spyOn(settingsService.storage, 'get').and.callFake((key: String): Promise<string> => {
            return new Promise((resolve, reject) => { resolve('url'); });
        });
    });

enter image description here

2 个答案:

答案 0 :(得分:0)

vikramarkaios,

您始终可以使用rootViewController属性

    UIActivityViewController *activity=[[UIActivityViewController alloc] initWithActivityItems:@[@"test" ] applicationActivities:nil];
[[UIApplication sharedApplication].windows.lastObject.rootViewController presentViewController:activity animated:YES completion:nil];

这将在所有其他视图上显示警告:)

修改

根据您编辑的问题,这是我的答案,我测试并且工作正常:)

 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Public Stock Report" message:NSLocalizedString(@"Your stock report...", nil) preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        //do whatever you want
    }];
    UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:@"Share" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        UIActivityViewController *activity=[[UIActivityViewController alloc] initWithActivityItems:@[@"test" ] applicationActivities:nil];
        [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:activity animated:YES completion:nil];
    }];
    [alertController addAction:cancelAction];
    [alertController addAction:settingsAction];
    [self presentViewController:alertController animated:YES completion:nil];

答案 1 :(得分:0)

点击分享按钮后,正确关闭您的视图,以便UIActivityViewController成为最顶级的视图。或者更好的是,在当前最顶级的视图中呈现UIActivityViewController。我希望这是有道理的。