Skip to content

Instantly share code, notes, and snippets.

@mpurbo
Created February 17, 2012 11:03
Show Gist options
  • Save mpurbo/1852689 to your computer and use it in GitHub Desktop.
Save mpurbo/1852689 to your computer and use it in GitHub Desktop.
geomon-client-ios: ライブラリの初期化
#import "MMGClient.h"
// アプリケーションのデリゲート。Geomonにログインするため、MMGRequestDelegateのプロトコルが実装される。
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate, MMGRequestDelegate>
// 他のプロパティの定義...
// Geomonのクライアントオブジェクト
@property (strong, nonatomic) MMGClient *client;
@end
// アプリケーションのデリゲートの実装
@implementation AppDelegate
@synthesize client = _client;
// 他のプロパティをシンセサイズする...
- (void)dealloc
{
// Geomonクライアントをリリースする。
[_client release];
// 他のプロパティをリリースする...
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// 他の初期化...
// Geomonクライアントを初期化する。
MMGClient *client = [[MMGClient alloc] initWithBaseURL:@"http://...."
projectSid:1234];
// Geomonにログインする。
[client loginWithId:@"testuser" password:@"testuser" delegate:self];
self.client = client;
[client release];
return YES;
}
#pragma mark - MMGRequestDelegateのプロトコルの実装
/**
Geomonに接続できました場合のコールバック。
*/
- (void)requestFinishedWithResponse:(MMGObject *)object
{
if (object.error != nil || object.type != kMMGUser) {
// ログインのエラーが発生しました。
NSLog(@"ユーザーオブジェクトの作成エラーが発生しました: %@", [object.error localizedDescription]);
} else {
// ログインできました。
MMGUser *user = (MMGUser *)object;
NSLog(@"ユーザーが正常にログインされました: %@", user);
}
}
/**
Geomonに接続するのは失敗の場合のコールバック。
*/
- (void)requestFailedWithError:(NSError *)error
{
NSLog(@"リクエストエラーが発生しました: %@", [error localizedDescription]);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment