Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1050276
  • 博文数量: 403
  • 博客积分: 10272
  • 博客等级: 上将
  • 技术积分: 4407
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-24 14:22
文章分类

全部博文(403)

文章存档

2012年(403)

分类: 嵌入式

2012-04-11 19:24:59

// NOTE: GameCenter does not guarantee that callback blocks will be execute on the main thread. // As such, your application needs to be very careful in how it handles references to view // controllers. If a view controller is referenced in a block that executes on a secondary queue, // that view controller may be released (and dealloc'd) outside the main queue. This is true // even if the actual block is scheduled on the main thread. In concrete terms, this code // snippet is not safe, even though viewController is dispatching to the main queue: // // [object doSomethingWithCallback: ^() // { // dispatch_async(dispatch_get_main_queue(), ^(void) // { // [viewController doSomething]; // }); // }]; // // UIKit view controllers should only be accessed on the main thread, so the snippet above may // lead to subtle and hard to trace bugs. Many solutions to this problem exist. In this sample, // I'm bottlenecking everything through "callDelegateOnMainThread" which calls "callDelegate". // Because "callDelegate" is the only method to access the delegate, I can ensure that delegate // is not visible in any of my block callbacks. - (void) callDelegate: (SEL) selector withArg: (id) arg error: (NSError*) err { assert([NSThread isMainThread]); if([delegate respondsToSelector: selector]) { if(arg != NULL) { [delegate performSelector: selector withObject: arg withObject: err]; } else { [delegate performSelector: selector withObject: err]; } } else { NSLog(@"Missed Method"); } } - (void) callDelegateOnMainThread: (SEL) selector withArg: (id) arg error: (NSError*) err { dispatch_async(dispatch_get_main_queue(), ^(void) { [self callDelegate: selector withArg: arg error: err]; }); } - (void) authenticateLocalUser { if([GKLocalPlayer localPlayer].authenticated == NO) { [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) { [self callDelegateOnMainThread: @selector(processGameCenterAuth:) withArg: NULL error: error]; }]; } }
南来地,北往的,上班的,下岗的,走过路过不要错过!

======================个性签名=====================

之前认为Apple 的iOS 设计的要比 Android 稳定,我错了吗?

下载的许多客户端程序/游戏程序,经常会Crash,是程序写的不好(内存泄漏?刚启动也会吗?)还是iOS本身的不稳定!!!

如果在Android手机中可以简单联接到ddms,就可以查看系统log,很容易看到程序为什么出错,在iPhone中如何得知呢?试试Organizer吧,分析一下Device logs,也许有用

阅读(1784) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~