小编Zoh*_*ved的帖子

UIApplicationDidBecomeActiveNotification和UIApplicationWillResignActiveNotification并非始终在Unity iOS App中触发

我创建了一个Unity iOS应用程序.我在团结中创建应用程序的原因是因为它可以轻松移植到其他平台.

我正在Axivity Sensors通过BLE技术进行沟通.一切都很好.但现在我想在后台运行应用程序.因此,我发现我应该使用UIApplicationDidBecomeActiveNotificationUIApplicationWillResignActiveNotification通知,以便我可以进行一些后台处理.

但有时,当App变得活跃或无效时,我不会收到通知.

有什么我做错了或者有更好的方法吗?

以下是代码:

-(id) init {

    self = [super init];

    if (!self) return nil;

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillTerminate:) name:UIApplicationWillTerminateNotification object:nil];

        return self;
    }

-(void)appWillResignActive:(NSNotification*)note {

    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(BLEOnCharactersticsUpdateNotification:)
                                             name:BLEOnCharactersticsUpdate object:nil]; 
}

-(void)appDidBecomeActive:(NSNotification*)note {

    NSLog(@"AppDidBecomeActive ");

    [[NSNotificationCenter defaultCenter] removeObserver:self name:BLEOnCharactersticsUpdate object:nil];

    for(int timeStampIndex = 0; timeStampIndex < [timeStampArray count]; timeStampIndex++) {

        NSLog(@"TimeStamp %i : Value : %@",timeStampIndex,[timeStampArray objectAtIndex:timeStampIndex]); …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c unity-game-engine ios

13
推荐指数
1
解决办法
653
查看次数

标签 统计

ios ×1

objective-c ×1

unity-game-engine ×1

xcode ×1