mirror of https://github.com/oxen-io/session-ios
Merge branch 'charlesmchen/appContext'
commit
94436f7b04
@ -0,0 +1,13 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import <SignalServiceKit/AppContext.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface MainAppContext : NSObject <AppContext>
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,29 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MainAppContext.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@implementation MainAppContext
|
||||
|
||||
- (BOOL)isMainApp
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)isMainAppAndActive
|
||||
{
|
||||
return [UIApplication sharedApplication].applicationState == UIApplicationStateActive;
|
||||
}
|
||||
|
||||
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:
|
||||
(BackgroundTaskExpirationHandler)expirationHandler
|
||||
{
|
||||
return [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:expirationHandler];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,22 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef void (^BackgroundTaskExpirationHandler)(void);
|
||||
|
||||
@protocol AppContext <NSObject>
|
||||
|
||||
- (BOOL)isMainApp;
|
||||
- (BOOL)isMainAppAndActive;
|
||||
|
||||
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:
|
||||
(BackgroundTaskExpirationHandler)expirationHandler;
|
||||
|
||||
@end
|
||||
|
||||
id<AppContext> CurrentAppContext();
|
||||
void SetCurrentAppContext(id<AppContext> appContext);
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,25 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AppContext.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
static id<AppContext> currentAppContext = nil;
|
||||
|
||||
id<AppContext> CurrentAppContext()
|
||||
{
|
||||
OWSCAssert(currentAppContext);
|
||||
|
||||
return currentAppContext;
|
||||
}
|
||||
|
||||
void SetCurrentAppContext(id<AppContext> appContext)
|
||||
{
|
||||
OWSCAssert(!currentAppContext);
|
||||
|
||||
currentAppContext = appContext;
|
||||
}
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
Loading…
Reference in New Issue