사용자가 KML 첨부 파일을 실행할 수 있도록 내 앱을 UTI와 연결했습니다. 내 유니버설 앱의 iPad 앱 대리인에서 launchOptions를 볼 수 있으며이 파일들에 대한 NSURL이 시작됩니다. 나는이 응용 프로그램에서 다른 곳에서 액세스 할 수 있도록 이것을 전역으로 저장하려고합니다. Engine이라는 단일 객체를 사용하여이 작업을 수행하고 있습니다.launchOptions NSURL을 전역 변수로 계속 사용합니다.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
Engine *myEngine=[Engine sharedInstance];
StormTrackIpad *newVC=[[StormTrackIpad alloc] initWithNibName:@"StormTrackIpad" bundle:nil];
[window addSubview:newVC.view];
NSURL *launchFileURL=(NSURL *)[launchOptions valueForKey:@"UIApplicationLaunchOptionsURLKey"];
myEngine.launchFile=launchFileURL;
/* Show details of launched file
NSString *message =launchFileURL.absoluteString;
NSString *title = [NSString stringWithFormat:@"Opening file"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
*/
[window makeKeyAndVisible];
return YES;
}
내 엔진 클래스는 다음과 같습니다 : 이것은 내 응용 프로그램 위임이다
// Engine.h
#import <Foundation/Foundation.h>
@interface Engine : NSObject {
NSURL *launchFile;
}
+ (Engine *) sharedInstance;
@property (nonatomic, retain) NSURL *launchFile;
@end
// Engine.m
#import "Engine.h"
@implementation Engine
@synthesize launchFile;
static Engine *_sharedInstance;
- (id) init
{
if (self = [super init])
{
// custom initialization
}
return self;
}
+ (Engine *) sharedInstance
{
if (!_sharedInstance)
{
_sharedInstance = [[Engine alloc] init];
}
return _sharedInstance;
}
@end
내 문제는 내가보기에서 (다른 곳에서 내 응용 프로그램의 엔진에서 launchFile 변수에 액세스하려고 할 때 Controller) 디버거는 Engine.launchFile의 값을 표시합니다. 이 변수에 액세스하고 있습니다 :
- (void)viewDidLoad {
[super viewDidLoad];
Engine *myEngine=[Engine sharedInstance];
NSURL *launchFile=myEngine.launchFile;
NSString *title = [NSString stringWithFormat:@"Opening file"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:launchFile.absoluteString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
어떤 도움이 필요합니까?
안녕하세요 샘, 제안한대로 키를 변경했습니다. myEngine.launchURL에 중단 점을 설정하는 것에 대해 잘 모릅니다 (myEngine.launchFile을 의미한다고해도). 어디에서/어떻게 설정하고 어떻게 볼 수 있습니까? 다른 앱 (Mail)에서 앱을 시작할 때 내 앱을 디버깅하는 방법을 모르겠습니다. myEngine.launchFile을 설정하고 View Controller에서 다음의 Log를 app delegate에 추가했습니다. 델리게이트에서는 올바른 URL을보고하고 VC에 null을보고합니다. \t NSLog (@ "launchFile URL : % @", myEngine.launchFile.absoluteString); 정말 감사드립니다. 감사합니다. JP –
아, 제안 된 오버라이드도 추가했습니다. :-) –
당신은 myEngine.launchURL에 대해 옳았습니다. - myEngine.launchFile을 의미했습니다! 다른 사람들이 그것을 읽고 더 명확하게하기 위해 질문을 변경했습니다 :) – deanWombourne