iOSiosios 开发常用

iOS应用内打开其他应用

2015-06-18  本文已影响2984人  Lonely__M
Paste_Image.png
#pragma mark
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    if (url)
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"你唤醒了您的应用" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alertView show];
    }
    
    return YES;
}
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(30, 10, 90, 90);
    [btn setTitle:@"按钮" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setBackgroundColor:[UIColor lightGrayColor]];
//    [btn addTarget:self action:@selector(dragMove:withEvent:) forControlEvents:UIControlEventTouchDragInside];
    [btn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
}

//跳转到demo1
- (void)btnAction
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mahong://"]];
}

- (void)dragMove:(UIButton *)sender withEvent:(UIEvent *)event
{
    sender.center = [[[event allTouches] anyObject] locationInView:self.view];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

如果想跳转到appStore,则写法如下:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps://"]];

附:[常用URL Schmes查询网站](http://handleopenurl.com/ 可以通过搜索主流app名称,找到URL Schemes,然后做应用内跳转,例如QQ的URL Schemes 为 mqq:open

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mqq:open//"]];
Paste_Image.png
上一篇下一篇

猜你喜欢

热点阅读