【问题标题】:Why its not showing anything when i open the app with url?为什么当我使用 url 打开应用程序时它没有显示任何内容?
【发布时间】:2017-02-20 00:53:57
【问题描述】:

我有以下设置,当我在 iPhone 7 中使用 url 打开我的应用程序(应用程序号 2 由应用程序号 1 使用 url 打开)时,我没有收到任何 url 输入。

它根本没有显示任何警报框。 我如何检查我是否在我的应用程序中收到了 url 输入?

AppDelegate.m:

#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return YES;
}

ViewController.m:

-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    //if (url != nil && [url isFileURL]) {
    //[self.ViewController handleOpenURL:url];
    //}
  id test = (NSURL *) url;
  UIAlertController * alert=   [UIAlertController
                                alertControllerWithTitle:@"My Title"
                                message:test
                                preferredStyle:UIAlertControllerStyleAlert];

  [self presentViewController:alert animated:YES completion:nil];
  //NSLog(@">>> got <<< >>> <<< !!!! >>>> : %@", url);
  return YES;
}

- (void)viewDidLoad {
  [super viewDidLoad];
}

【问题讨论】:

    标签: ios objective-c iphone url-scheme


    【解决方案1】:

    问题是

    -(BOOL) application:(UIApplication *)application 
        openURL:(NSURL *)url 
        sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
    

    ... 是一个 UIApplicationDelegate 方法。所以它不能位于 ViewController.m 中。它需要在 AppDelegate.m 中。

    【讨论】:

    • 我现在把它放在 AppDelegate.m 中,但是我收到了一个错误 /Users/sun/Desktop/iphone/AppDelegate.m:16:9: No visible @interface for 'AppDelegate' declares the selector 'presentViewController:animated:completion:'
    • 当然,你会遇到完全不同的错误。但这不是你问的。问题是“那么我没有得到任何 url 输入”。好吧,现在你是!所以这个问题就解决了。完毕。把present的东西拿出来,把NSLog放回去,你会看到的。
    猜你喜欢
    • 2014-03-08
    • 1970-01-01
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多