iOS 两个app之间的跳转

来源:互联网 发布:php培训机构达内教育 编辑:程序博客网 时间:2024/03/29 21:05

朋友突然问到我这个问题,自己研究了会。简单的两个app之间的跳转。写了个demo给他了。下面是做的demo。

首先创建第一个叫jumpTest3的项目 在项目


添加完成之后。运行在模拟器上一下。
接着创建第二个叫jumpTest2的项目,在项目的Info.plist添加如下字段

添加上去。
然后再jumpTest2中实现

- (void)viewDidLoad {

  [superviewDidLoad];

  

  //添加红色的按钮

  UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];

  button.backgroundColor = [UIColorredColor];

  button.frame=CGRectMake(100,100,100,100);

  [button addTarget:selfaction:@selector(clickJumeToAnotherApp)forControlEvents:UIControlEventTouchUpInside];

  [self.viewaddSubview:button];

}

//点击红色按钮的时候去跳转

-(void)clickJumeToAnotherApp{


  NSString *jumpString = [NSStringstringWithFormat:@"jumpTest3://hello"];


  BOOL canOpen = [[UIApplicationsharedApplication]canOpenURL:[NSURLURLWithString:jumpString]];

  

  NSLog(@"canOpen %d",canOpen);

  if (canOpen) {

    

    [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:jumpString]];

    

  }else{

  

    UIAlertView *alertView =[[UIAlertViewalloc]initWithTitle:@"未安装"message:@"友情提示"delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil,nil];

    

    [alertView show];

    

  }

  

  

}

本人菜鸟,以上都是自己的理解,有什么不对的地方,或者不合适的地方求大神指出来。谢谢大家了



0 0