Pregunta

he asociado mi aplicación con una infección urinaria por lo que los usuarios pueden iniciar datos adjuntos KML. En la aplicación del iPad delegado de mi aplicación universal puedo ver los launchOptions y de éstos Puedo obtener una NSURL para el archivo que se puso en marcha. Quiero guardar esto como una manera global que pueda acceder a él desde otro lugar en mi aplicación, estoy haciendo esto usando un conjunto unitario llamado motor. Esta es mi aplicación Delegado:

- (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;
}

Mi motor miradas clase como esta:

//  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

Mi problema es que cuando intento acceder a la variable LaunchFile del motor en otra parte de mi aplicación (desde un controlador de vista) los espectáculos del depurador el valor de Engine.launchFile sea. Yo soy el acceso a la variable de la siguiente manera:

- (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]; 
}

Cualquier ayuda?

¿Fue útil?

Solución

Su código se ve bien a primera vista - se puede establecer un punto de interrupción en myEngine.launchFile = sólo para ver qué myEngine está señalando a? Esto debe asegurarse de que su código de producto único está trabajando.

Además, han comprobado que [launchOptions valueForKey: @ "UIApplicationLaunchOptionsURLKey"] definitivamente devuelve un objeto? Quiso decir que escribir esto:

[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];

Sam

P Usted debe leer la respuesta a esta pregunta en la creación de objetos únicos, hay algunas anulaciones que se debe poner en su clase de motor;)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top