0

ボタンをタップするとすぐに、ActivityIndi​​cator を使用して Loading UIAlertView をポップアップさせようとしています。その瞬間、dpkgコマンドを実行するために必要です。

私はそれを完成させることに非常に近づいています。ボタンをタッチすると、アプリがdebianパッケージをインストールしている間、UIAlertViewが完全に読み込まれません(画面が暗くなります)。パッケージのインストールが完了するとすぐに、UIAlertView が一瞬ロードされます。その後、で却下されます[alert dismissWithClickedButtonIndex:0 animated:YES];

これが別のスレッドにある必要があるかどうかわからないので、そうしようとしました。正しく設定できているかどうかわかりません。だからここに私のコードがあります。提案?修正?

.m

-(IBAction)installdeb:(id)sender{
    UIAlertView *alerty = [[UIAlertView alloc] initWithTitle:@"Installing..." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
    progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    [alerty addSubview:progress];
    [progress startAnimating];
    [alerty show];
    [alerty release];
    [NSThread detachNewThreadSelector:@selector(installdeb) toTarget:self withObject:nil];
}

- (void)installdeb{

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    char *installdebchar = [[NSString stringWithString:@"dpkg -i /Applications/MyApp.app/package.deb"] UTF8String];
    system(installdebchar);
    if (system(installdebchar) == 0){
        [alerty dismissWithClickedButtonIndex:0 animated:YES];
        UIImage *img1 = [UIImage imageNamed:@"whitecheckmark.png"];
        [ImageView1 setImage:img1];
    } else {
        [alerty dismissWithClickedButtonIndex:0 animated:YES];
    }
    [pool release];
}

.h

@class DebInstallViewController;

@interface DebInstallViewController : UIViewController <UINavigationBarDelegate, UINavigationControllerDelegate, UIAlertViewDelegate>{

    IBOutlet UIAlertView *alert;

    IBOutlet UIImageView *ImageView1;

}

- (IBAction)installdeb:(id)sender;

@end

私は客観的なcにちょっと慣れていません。だから嫌いにならないで。:) 提案?

4

1 に答える 1

1

あなたは正しい全体的なアプローチを取っているようです。ただし、いくつかの問題があります。まず、'alerty' が 'installdeb' のどこから来ているのか不明です。メンバー変数「アラート」を使用するつもりだったと思いますか?

その場合、コードで確認できる主な低レベルの問題は、バックグラウンド スレッドで DismissWithClickedButtonIndex:animated: を呼び出そうとしていることです。Apple のドキュメントには、特に明記されていない限り、すべての UIKit のやり取りはメイン スレッドで行われなければならないと記載されています。

アラート ivar を割り当てるときに、それが適切に保持されることを確認してください。

さて、iOS アプリのように見えるものからシステムコマンドを呼び出しているという高レベルの問題があります...しかし、あなたがそこで何をしているのかを知っていると仮定します...

于 2012-01-15T08:38:27.307 に答える