Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue when using Bugsnag on a WatchOS app #1588

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions Bugsnag.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,14 @@
01FF490728BF8B7B001F817B /* BugsnagInternals.h in Headers */ = {isa = PBXBuildFile; fileRef = 01FF490528BF8B7B001F817B /* BugsnagInternals.h */; };
01FF490828BF8B7B001F817B /* BugsnagInternals.h in Headers */ = {isa = PBXBuildFile; fileRef = 01FF490528BF8B7B001F817B /* BugsnagInternals.h */; };
01FF490928BF8B7B001F817B /* BugsnagInternals.h in Headers */ = {isa = PBXBuildFile; fileRef = 01FF490528BF8B7B001F817B /* BugsnagInternals.h */; };
093EB6602AFE447E006EB7E3 /* Swizzle.mm in Sources */ = {isa = PBXBuildFile; fileRef = 093EB65F2AFE447E006EB7E3 /* Swizzle.mm */; };
093EB6612AFE447E006EB7E3 /* Swizzle.mm in Sources */ = {isa = PBXBuildFile; fileRef = 093EB65F2AFE447E006EB7E3 /* Swizzle.mm */; };
093EB6622AFE447E006EB7E3 /* Swizzle.mm in Sources */ = {isa = PBXBuildFile; fileRef = 093EB65F2AFE447E006EB7E3 /* Swizzle.mm */; };
093EB6632AFE447E006EB7E3 /* Swizzle.mm in Sources */ = {isa = PBXBuildFile; fileRef = 093EB65F2AFE447E006EB7E3 /* Swizzle.mm */; };
093EB6662AFE4580006EB7E3 /* BSGTestCase.mm in Sources */ = {isa = PBXBuildFile; fileRef = 093EB6652AFE4580006EB7E3 /* BSGTestCase.mm */; };
093EB6672AFE4580006EB7E3 /* BSGTestCase.mm in Sources */ = {isa = PBXBuildFile; fileRef = 093EB6652AFE4580006EB7E3 /* BSGTestCase.mm */; };
093EB6682AFE4580006EB7E3 /* BSGTestCase.mm in Sources */ = {isa = PBXBuildFile; fileRef = 093EB6652AFE4580006EB7E3 /* BSGTestCase.mm */; };
093EB6692AFE4580006EB7E3 /* BSGTestCase.mm in Sources */ = {isa = PBXBuildFile; fileRef = 093EB6652AFE4580006EB7E3 /* BSGTestCase.mm */; };
3A700A9424A63ABC0068CD1B /* BugsnagThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 3A700A8024A63A8E0068CD1B /* BugsnagThread.h */; settings = {ATTRIBUTES = (Public, ); }; };
3A700A9524A63AC50068CD1B /* BugsnagSession.h in Headers */ = {isa = PBXBuildFile; fileRef = 3A700A8124A63A8E0068CD1B /* BugsnagSession.h */; settings = {ATTRIBUTES = (Public, ); }; };
3A700A9624A63AC60068CD1B /* BugsnagStackframe.h in Headers */ = {isa = PBXBuildFile; fileRef = 3A700A8224A63A8E0068CD1B /* BugsnagStackframe.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -1539,6 +1547,10 @@
01E8765D256684E700F4B70A /* URLSessionMock.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = URLSessionMock.m; sourceTree = "<group>"; };
01F9FCB528929336005EDD8C /* BSGSerializationTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BSGSerializationTests.m; sourceTree = "<group>"; };
01FF490528BF8B7B001F817B /* BugsnagInternals.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BugsnagInternals.h; sourceTree = "<group>"; };
093EB65E2AFE447E006EB7E3 /* Swizzle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Swizzle.h; sourceTree = "<group>"; };
093EB65F2AFE447E006EB7E3 /* Swizzle.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Swizzle.mm; sourceTree = "<group>"; };
093EB6642AFE4580006EB7E3 /* BSGTestCase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BSGTestCase.h; sourceTree = "<group>"; };
093EB6652AFE4580006EB7E3 /* BSGTestCase.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BSGTestCase.mm; sourceTree = "<group>"; };
3A700A8024A63A8E0068CD1B /* BugsnagThread.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BugsnagThread.h; sourceTree = "<group>"; };
3A700A8124A63A8E0068CD1B /* BugsnagSession.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BugsnagSession.h; sourceTree = "<group>"; };
3A700A8224A63A8E0068CD1B /* BugsnagStackframe.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BugsnagStackframe.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1934,8 +1946,6 @@
00AD1C7F24869B0E00A27979 /* BugsnagTests */ = {
isa = PBXGroup;
children = (
CBEC893E2A4ACD230088A3CE /* FileBasedTest.h */,
CBEC893F2A4ACD230088A3CE /* FileBasedTest.m */,
019480D32625F3EB00E833ED /* BSGAppKitTests.m */,
008966BD2486D43500DC48C2 /* BSGClientObserverTests.m */,
00896A3F2486DBDD00DC48C2 /* BSGConfigurationBuilderTests.m */,
Expand All @@ -1953,6 +1963,8 @@
01F9FCB528929336005EDD8C /* BSGSerializationTests.m */,
CB6419AA25A73E8C00613D25 /* BSGStorageMigratorV0V1Tests.m */,
017DCF9A287422BB000ECB22 /* BSGTelemetryTests.m */,
093EB6642AFE4580006EB7E3 /* BSGTestCase.h */,
093EB6652AFE4580006EB7E3 /* BSGTestCase.mm */,
01DE903B26CEAF9E00455213 /* BSGUtilsTests.m */,
CB9103632502320A00E9D1E2 /* BugsnagApiClientTest.m */,
E701FA9E2490EF4A008D842F /* BugsnagApiValidationTest.m */,
Expand Down Expand Up @@ -1995,9 +2007,13 @@
E701FAAE2490EFE8008D842F /* ConfigurationApiValidationTest.m */,
01BDB21425DEC02900A91FAF /* Data */,
E701FAAA2490EFD9008D842F /* EventApiValidationTest.m */,
CBEC893E2A4ACD230088A3CE /* FileBasedTest.h */,
CBEC893F2A4ACD230088A3CE /* FileBasedTest.m */,
00E636C324878FFC006CBF1A /* Info.plist */,
01B14C55251CE55F00118748 /* report-react-native-promise-rejection.json */,
008966B72486D43500DC48C2 /* report.json */,
093EB65E2AFE447E006EB7E3 /* Swizzle.h */,
093EB65F2AFE447E006EB7E3 /* Swizzle.mm */,
004E35392487B375007FBAE4 /* Tests-Bridging-Header.h */,
CBA22499251E429C00B87416 /* TestSupport.h */,
CBA2249A251E429C00B87416 /* TestSupport.m */,
Expand Down Expand Up @@ -3149,6 +3165,7 @@
0089679F2486D43700DC48C2 /* KSCrashSentry_Tests.m in Sources */,
008967872486D43700DC48C2 /* KSCrashSentry_NSException_Tests.m in Sources */,
0089679C2486D43700DC48C2 /* KSFileUtils_Tests.m in Sources */,
093EB6602AFE447E006EB7E3 /* Swizzle.mm in Sources */,
008966EE2486D43700DC48C2 /* BugsnagClientPayloadInfoTest.m in Sources */,
010F80C228645B4200D6569E /* BSGDefinesTests.m in Sources */,
01BDB1F525DEBFB200A91FAF /* BSGEventUploadKSCrashReportOperationTests.m in Sources */,
Expand All @@ -3168,6 +3185,7 @@
008967152486D43700DC48C2 /* BugsnagCollectionsTests.m in Sources */,
01E8765E256684E700F4B70A /* URLSessionMock.m in Sources */,
008967AB2486D43700DC48C2 /* BSG_KSMachTests.m in Sources */,
093EB6662AFE4580006EB7E3 /* BSGTestCase.mm in Sources */,
0089672A2486D43700DC48C2 /* BugsnagStacktraceTest.m in Sources */,
01847DAC26441A5E00ADA4C7 /* BSGInternalErrorReporterTests.m in Sources */,
0163BF5925823D8D008DC28B /* BSGNotificationBreadcrumbsTests.m in Sources */,
Expand Down Expand Up @@ -3315,6 +3333,7 @@
008967822486D43700DC48C2 /* KSSystemInfo_Tests.m in Sources */,
008967612486D43700DC48C2 /* BugsnagBreadcrumbsTest.m in Sources */,
01DE903D26CEAF9E00455213 /* BSGUtilsTests.m in Sources */,
093EB6672AFE4580006EB7E3 /* BSGTestCase.mm in Sources */,
CB156242270707740097334C /* KSCrashNames_Test.m in Sources */,
008967012486D43700DC48C2 /* BugsnagEventPersistLoadTest.m in Sources */,
0089671C2486D43700DC48C2 /* BugsnagSessionTest.m in Sources */,
Expand All @@ -3341,6 +3360,7 @@
004E353B2487B3B3007FBAE4 /* BugsnagSwiftPublicAPITests.swift in Sources */,
0089677C2486D43700DC48C2 /* RFC3339DateTool_Tests.m in Sources */,
CBEC89412A4ACD240088A3CE /* FileBasedTest.m in Sources */,
093EB6612AFE447E006EB7E3 /* Swizzle.mm in Sources */,
01A2958728B667C2005FCC8C /* BSGNetworkBreadcrumbTests.m in Sources */,
008967552486D43700DC48C2 /* BugsnagOnCrashTest.m in Sources */,
008967A02486D43700DC48C2 /* KSCrashSentry_Tests.m in Sources */,
Expand Down Expand Up @@ -3481,6 +3501,7 @@
01B6BB7E25D5777F00FC4DE6 /* BugsnagSwiftPublicAPITests.swift in Sources */,
0089677A2486D43700DC48C2 /* BSG_KSMachHeadersTests.m in Sources */,
0089672C2486D43700DC48C2 /* BugsnagStacktraceTest.m in Sources */,
093EB6682AFE4580006EB7E3 /* BSGTestCase.mm in Sources */,
008966F32486D43700DC48C2 /* BugsnagMetadataRedactionTest.m in Sources */,
008967382486D43700DC48C2 /* BugsnagMetadataTests.m in Sources */,
008967832486D43700DC48C2 /* KSSystemInfo_Tests.m in Sources */,
Expand Down Expand Up @@ -3514,6 +3535,7 @@
008967442486D43700DC48C2 /* BugsnagSessionTrackerStopTest.m in Sources */,
CB26E9BC28350E0C005A1865 /* UISceneStub.m in Sources */,
008967982486D43700DC48C2 /* KSCrashState_Tests.m in Sources */,
093EB6622AFE447E006EB7E3 /* Swizzle.mm in Sources */,
008967772486D43700DC48C2 /* XCTestCase+KSCrash.m in Sources */,
01A2958828B667C2005FCC8C /* BSGNetworkBreadcrumbTests.m in Sources */,
CBEC89422A4ACD240088A3CE /* FileBasedTest.m in Sources */,
Expand Down Expand Up @@ -3748,7 +3770,9 @@
CB28F0B828294DE1003AB200 /* BSGConfigurationBuilderTests.m in Sources */,
CB28F0DB282A4BA6003AB200 /* BugsnagMetadataTests.m in Sources */,
CB28F0B028294D4F003AB200 /* KSFileUtils_Tests.m in Sources */,
093EB6632AFE447E006EB7E3 /* Swizzle.mm in Sources */,
CB28F0DC282A4BEE003AB200 /* BugsnagSessionTrackerTest.m in Sources */,
093EB6692AFE4580006EB7E3 /* BSGTestCase.mm in Sources */,
CB28F0B728294DE1003AB200 /* BSGFeatureFlagStoreTests.m in Sources */,
010F80C528645B4200D6569E /* BSGDefinesTests.m in Sources */,
CB28F0A028294D44003AB200 /* BSG_KSFileTests.m in Sources */,
Expand Down
22 changes: 18 additions & 4 deletions Bugsnag/Helpers/BSGRunContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,15 @@ static bool GetIsActive(void) {
#endif

#if TARGET_OS_WATCH
WKExtension *ext = [WKExtension sharedExtension];
return ext && ext.applicationState == WKApplicationStateActive;
if ([BSG_KSSystemInfo isRunningInAppExtension]) {
WKExtension *ext = [WKExtension sharedExtension];
return ext && ext.applicationState == WKApplicationStateActive;
} else if (@available(watchOS 7.0, *)) {
WKApplication *app = [WKApplication sharedApplication];
return app && app.applicationState == WKApplicationStateActive;
} else {
return true;
}
#endif
}

Expand Down Expand Up @@ -170,8 +177,15 @@ static bool GetIsForeground(void) {
#endif

#if TARGET_OS_WATCH
WKExtension *ext = [WKExtension sharedExtension];
return ext && ext.applicationState != WKApplicationStateBackground;
if ([BSG_KSSystemInfo isRunningInAppExtension]) {
WKExtension *ext = [WKExtension sharedExtension];
return ext && ext.applicationState != WKApplicationStateBackground;
} else if (@available(watchOS 7.0, *)) {
WKApplication *app = [WKApplication sharedApplication];
return app && app.applicationState == WKApplicationStateBackground;
} else {
return true;
}
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ - (void)resetBreadcrumbs {
}

- (void)setUp {
[super setUp];
[BSGURLSessionTracingDelegate setClient:(id)self];
[self resetBreadcrumbs];
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/BugsnagTests/BSGAppKitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Copyright © 2021 Bugsnag Inc. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "BSGTestCase.h"

@interface BSGAppKitTests : XCTestCase
@interface BSGAppKitTests : BSGTestCase

@end

Expand Down
5 changes: 3 additions & 2 deletions Tests/BugsnagTests/BSGClientObserverTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2020 Bugsnag. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "BSGTestCase.h"

#import "Bugsnag.h"
#import "BugsnagClient+Private.h"
Expand All @@ -15,7 +15,7 @@
#import "BugsnagMetadata+Private.h"
#import "BugsnagUser+Private.h"

@interface BSGClientObserverTests : XCTestCase
@interface BSGClientObserverTests : BSGTestCase
@property BugsnagClient *client;
@property BSGClientObserverEvent event;
@property id value;
Expand All @@ -24,6 +24,7 @@ @interface BSGClientObserverTests : XCTestCase
@implementation BSGClientObserverTests

- (void)setUp {
[super setUp];
BugsnagConfiguration *config = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1];
self.client = [Bugsnag startWithConfiguration:config];

Expand Down
4 changes: 2 additions & 2 deletions Tests/BugsnagTests/BSGConfigurationBuilderTests.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#import <XCTest/XCTest.h>
#import "BSGTestCase.h"

#import <Bugsnag/Bugsnag.h>
#import "BSGConfigurationBuilder.h"
#import "BugsnagConfiguration+Private.h"
#import "BugsnagTestConstants.h"
#import <TargetConditionals.h>

@interface BSGConfigurationBuilderTests : XCTestCase
@interface BSGConfigurationBuilderTests : BSGTestCase
@end

@implementation BSGConfigurationBuilderTests
Expand Down
4 changes: 2 additions & 2 deletions Tests/BugsnagTests/BSGConnectivityTest.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#import <XCTest/XCTest.h>
#import "BSGTestCase.h"

#import "BSGConnectivity.h"
#import "BSGDefines.h"

@interface BSGConnectivityTest : XCTestCase
@interface BSGConnectivityTest : BSGTestCase
@end

@implementation BSGConnectivityTest
Expand Down
4 changes: 2 additions & 2 deletions Tests/BugsnagTests/BSGDefinesTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// Copyright © 2022 Bugsnag Inc. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "BSGTestCase.h"

#import "BSGDefines.h"

@interface BSGDefinesTests : XCTestCase
@interface BSGDefinesTests : BSGTestCase

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
// Copyright © 2021 Bugsnag Inc. All rights reserved.
//

#import "BSGTestCase.h"

#import <Bugsnag/Bugsnag.h>
#import <XCTest/XCTest.h>

#import "BSGEventUploadKSCrashReportOperation.h"
#import "BSGInternalErrorReporter.h"

@interface BSGEventUploadKSCrashReportOperationTests : XCTestCase
@interface BSGEventUploadKSCrashReportOperationTests : BSGTestCase

@property NSString *errorClass;
@property NSString *context;
Expand Down
6 changes: 3 additions & 3 deletions Tests/BugsnagTests/BSGFeatureFlagStoreTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// Copyright © 2021 Bugsnag Inc. All rights reserved.
//

#import "BSGFeatureFlagStore.h"
#import "BSGTestCase.h"

#import <XCTest/XCTest.h>
#import "BSGFeatureFlagStore.h"

@interface BSGFeatureFlagStoreTests : XCTestCase
@interface BSGFeatureFlagStoreTests : BSGTestCase

@end

Expand Down
5 changes: 3 additions & 2 deletions Tests/BugsnagTests/BSGInternalErrorReporterTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2021 Bugsnag Inc. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "BSGTestCase.h"

#import <Bugsnag/Bugsnag.h>

Expand All @@ -18,7 +18,7 @@
#import "BugsnagNotifier.h"
#import "BSGPersistentDeviceID.h"

@interface BSGInternalErrorReporterTests : XCTestCase
@interface BSGInternalErrorReporterTests : BSGTestCase

@property (nonatomic) BugsnagConfiguration *configuration;

Expand All @@ -27,6 +27,7 @@ @interface BSGInternalErrorReporterTests : XCTestCase
@implementation BSGInternalErrorReporterTests

- (void)setUp {
[super setUp];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
[BSGInternalErrorReporter setSharedInstance:nil];
Expand Down
4 changes: 2 additions & 2 deletions Tests/BugsnagTests/BSGJSONSerializationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// Copyright © 2020 Bugsnag Inc. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "BSGTestCase.h"

#import "BSGJSONSerialization.h"

@interface BSGJSONSerializationTests : XCTestCase
@interface BSGJSONSerializationTests : BSGTestCase
@end

@implementation BSGJSONSerializationTests
Expand Down
6 changes: 3 additions & 3 deletions Tests/BugsnagTests/BSGNetworkBreadcrumbTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// Created by Nick Dowell on 22/09/2021.
//

#import "BSGNetworkBreadcrumb.h"
#import "BSGTestCase.h"

#import <XCTest/XCTest.h>
#import "BSGNetworkBreadcrumb.h"

@interface BSGNetworkBreadcrumbTests : XCTestCase
@interface BSGNetworkBreadcrumbTests : BSGTestCase

@end

Expand Down
5 changes: 3 additions & 2 deletions Tests/BugsnagTests/BSGNotificationBreadcrumbsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2020 Bugsnag Inc. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "BSGTestCase.h"

#import <Bugsnag/Bugsnag.h>

Expand All @@ -19,7 +19,7 @@
#endif


@interface BSGNotificationBreadcrumbsTests : XCTestCase <BSGBreadcrumbSink>
@interface BSGNotificationBreadcrumbsTests : BSGTestCase <BSGBreadcrumbSink>

@property NSNotificationCenter *notificationCenter;
@property id notificationObject;
Expand Down Expand Up @@ -114,6 +114,7 @@ @implementation BSGNotificationBreadcrumbsTests
#pragma mark Setup

- (void)setUp {
[super setUp];
self.breadcrumb = nil;
BugsnagConfiguration *configuration = [[BugsnagConfiguration alloc] initWithApiKey:@"0192837465afbecd0192837465afbecd"];
self.notificationBreadcrumbs = [[BSGNotificationBreadcrumbs alloc] initWithConfiguration:configuration breadcrumbSink:self];
Expand Down
4 changes: 2 additions & 2 deletions Tests/BugsnagTests/BSGOutOfMemoryTests.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import <XCTest/XCTest.h>
#import "BSGTestCase.h"

#import "BSGFileLocations.h"
#import "BSGRunContext.h"
Expand All @@ -10,7 +10,7 @@
#import "BugsnagSystemState.h"
#import "BugsnagTestConstants.h"

@interface BSGOutOfMemoryTests : XCTestCase
@interface BSGOutOfMemoryTests : BSGTestCase
@end

@implementation BSGOutOfMemoryTests
Expand Down
5 changes: 3 additions & 2 deletions Tests/BugsnagTests/BSGRunContextTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
// Copyright © 2022 Bugsnag Inc. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "BSGTestCase.h"

#import "BSGFileLocations.h"
#import "BSGRunContext.h"

@interface BSGRunContextTests : XCTestCase
@interface BSGRunContextTests : BSGTestCase

@end

@implementation BSGRunContextTests

- (void)setUp {
[super setUp];
if (!bsg_runContext) {
BSGRunContextInit(BSGFileLocations.current.runContext);
}
Expand Down
Loading
Loading