应用被其他程序打开时,如何切换至根视图

hhh_hao 2014-04-03 02:49:55
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {}

应用被其他程序打开,并回调上面的函数时, 想将当前的应用切换至主屏幕, 怎么实现? 谢谢高手指点
...全文
112 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hhh_hao 2014-04-04
  • 打赏
  • 举报
回复
多谢楼上的回答, 如果上述的url是个媒体文件 的路径,我如果根据这个路径生成ALAsset? 或者如何获取这个媒体文件的信息
hhh_hao 2014-04-04
  • 打赏
  • 举报
回复
引用 3 楼 wangliangffaflgh 的回复:


    ALAssetsLibrary* alLibrary = [[ALAssetsLibrary alloc] init];
    NSURL *urlstr = [NSURL URLWithString:@"http://......"];
    [alLibrary assetForURL:urlstr resultBlock:^(ALAsset *asset) {
        
    } failureBlock:^(NSError *error) {
        
    }];
asset的值为nil, 传过来的url 为 @“file:///private/var/mobile/.../Documents/inbox/...jpg”
hhh_hao 2014-04-04
  • 打赏
  • 举报
回复
引用 1 楼 wangliangffaflgh 的回复:

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    if ([sourceApplication isEqualToString:@"com.yourapp.AppName"])  //com.yourapp.AppName为调用者应用的bundle id
    {
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
/*这两句和这个里面一样
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
    } else {
        self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease];
    }
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}
*/
    }
    
    return YES;
}
调用了没有效果
测试NULL 2014-04-04
  • 打赏
  • 举报
回复


    ALAssetsLibrary* alLibrary = [[ALAssetsLibrary alloc] init];
    NSURL *urlstr = [NSURL URLWithString:@"http://......"];
    [alLibrary assetForURL:urlstr resultBlock:^(ALAsset *asset) {
        
    } failureBlock:^(NSError *error) {
        
    }];
测试NULL 2014-04-03
  • 打赏
  • 举报
回复

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    if ([sourceApplication isEqualToString:@"com.yourapp.AppName"])  //com.yourapp.AppName为调用者应用的bundle id
    {
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
/*这两句和这个里面一样
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
    } else {
        self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease];
    }
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}
*/
    }
    
    return YES;
}

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧