iPhoneのサンプルプログラム

SATCHを用いたナビアプリ(1)の参考アプリ2

AppDelegate.h
#import <UIKit/UIKit.h>
#import "satchARViewer.h"

@interface AppDelegate : NSObject 
{
    UIWindow *window;
    SatchARViewer *mPlayer;
    
    NSString *start_pos;
    IBOutlet UIButton *btnCorner;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (retain, nonatomic) IBOutlet UIView *mRender;
@property (retain, nonatomic) IBOutlet UILabel *labMsg;

- (void)start;
- (void)stop;

@end

AppDelegate.mm
#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window;
@synthesize mRender;
@synthesize labMsg;

- (void)dealloc
{
    [self stop];
    
    if (mPlayer) {
        [mPlayer terminate];
        [mPlayer release];
        mPlayer = nil;
    }
    
    [window release];
    [mRender release];
    [labMsg release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    btnCorner.enabled = NO;
    
    [SatchARViewer setDialogMessageLoading:@"ロ−ディング..."];
    [SatchARViewer
     setToastMessageNoNetworkConnection:@"ネットワークに接続されていません。"];
    [SatchARViewer setToastMessageNetworkError:@"通信中にエラーが発生しました。"];
    [SatchARViewer setToastMessageLicenceError:@"認証に失敗しました。"];
    
    [window addSubview:mRender];
    
    mPlayer = [[[SatchARViewer alloc] init] initialize:mRender];
    
    [self.window makeKeyAndVisible];
    [self start];
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    if (mPlayer != nil) {
        [mPlayer applicationWillResignActive];
    }
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    if (mPlayer != nil) {
        [mPlayer applicationDidEnterBackground];
    }
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    if (mPlayer != nil) {
        [mPlayer applicationWillEnterForeground];
    }
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    if (mPlayer != nil) {
        [mPlayer applicationDidBecomeActive];
    }
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    if (mPlayer != nil) {
        [mPlayer applicationWillTerminate];
    }
}

- (void)callback:(NSNumber*)num
{
    switch ([num intValue]) {
        case LOAD_SCENARIO_STATUS_COMPLETE:
            [mPlayer registerCommunicationCallback:@"setStartPosition" 
                    callbackObject:self 
                    callbackMethod:@"TI_SetStartPosNotification"];
            [[NSNotificationCenter defaultCenter] addObserver:self
                    selector:@selector(setStartPosition:) 
                    name:@"TI_SetStartPosNotification" 
                    object:nil];
            [mPlayer playScenario];
            labMsg.text = @"出発地のマーカをかざしてください!";

            break;
    }
}

- (void)start
{
    if (mPlayer) {
        [mPlayer loadScenario:@"Nov4_iphone/Nov4.dpd"
                     callback:@selector(callback:)
                          obj:self];
    }
}

- (void)stop
{
    if (mPlayer && ![mPlayer isScenarioPaused]) {
        [mPlayer playScenario];
    }
}

- (void)setStartPosition:(NSNotification *)notification
{
    NSDictionary* l_userInfo = [notification userInfo];
    start_pos = (NSString *)[l_userInfo objectForKey:@"arg0"];
    
    labMsg.text = [NSString stringWithFormat:@"出発地:%@", start_pos];
}


@end