1

我正在更新我的一个 iPhone 应用程序。我需要做一些我从未做过的事情...

我想在 Safari 浏览器中使用 UIAlert “一次性代码”启动一个 URL。

让我再解释一下:如果我想使用 UIAlert 启动 Safari,我可以轻松编写如下内容:

- (void)OpenApple:(id)sender {

    UIAlertView *URLApple = [[UIAlertView alloc] initWithTitle: NSLocalizedString(@"Open Apple",@"Open") message: NSLocalizedString(@"Want you open Apple",@"Apple") delegate: self cancelButtonTitle: NSLocalizedString(@"No", @"close") otherButtonTitles: NSLocalizedString(@"Yes", @"yes"), nil];
    alertView.tag = TAG_URL;
    [alertView show];
    [alertView release];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        if ( alertView.tag == TAG_URL ) {
        NSLog(@"Clicked button index 0");
        // Do nothing
        }} else {
        if ( alertView.tag == TAG_URL ){
        NSLog(@"Clicked button index other than 0");
        NSURL *url = [NSURL URLWithString: NSLocalizedString(@"http://www.apple.com", @"URLApple")];
            if ([[UIApplication sharedApplication] canOpenURL:url]) {
                [[UIApplication sharedApplication] openURL:url];
}}}}

但是现在,我想一次性完成“这2(无效)”......

简而言之,我需要在上面摘录的第一部分打开外部 URL。

有点像:

"UIAlertView *URLApple = [[UIAlertView alloc] initWithTitle: NSLocalizedString(@"Open Apple",@"Open") 消息:NSLocalizedString(@"Want you open Apple",@"Apple") 委托:self cancelButtonTitle: NSLocalizedString(@ "No", @"close") otherButtonTitles: NSLocalizedString(@"Yes", @"yes"), nil]; alertView.tag = TAG_URL; [alertView show]; [alertView release];

如果@"yes" = [[UIApplication sharedApplication] canOpenURL:url] }"

另一方面,我不能写这样的东西: -(void) alertView: (UIAlertView *)alert1: clickedButtonAtIndex:(NSInteger)buttonIndex{ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://apple. com"]];

太容易了...... 我必须需要以我用作示例的代码的第一部分开头的东西 (void)OpenApple:(id)sender {

UIAlertView *URLApple = [[UIAlertView alloc] initWithTitle: NSLocalizedString(@"Open Apple",@"Open") 消息:NSLocalizedString(@"Want you open Apple",@"Apple") 委托:self cancelButtonTitle: NSLocalizedString(@" No", @"close") otherButtonTitles: NSLocalizedString(@"Yes", @"yes"), nil]; alertView.tag = TAG_URL; [警报视图显示];[alertView 发布];}

代码的第一部分必须包含我必须打开的 URL...

我必须以这种方式编写代码,因为我需要打开的 URL(不是网站的 URL...)在任何情况下都不能发送到我的代码的另一部分(另一个“-(void)”,总共)。警报、触发打开 URL 的警报按钮和 URL 本身必须位于我的代码的同一部分。

可能吗?你对此深思吗?

在此先感谢谁能帮助我。

最好的问候, CCC。

4

0 回答 0