Skip to content

Commit 3ba6847

Browse files
authored
Merge pull request #292 from Countly/visionos_support
visionOS support
2 parents 9a1dd44 + 591d346 commit 3ba6847

18 files changed

+67
-62
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ jobs:
2525
{os_version: 14, sdk: "iphoneos17.5"},
2626
{os_version: 14, sdk: "appletvos17.5"},
2727
{os_version: 14, sdk: "watchos10.5"},
28-
{os_version: 14, sdk: "visionos1.2"},
28+
{os_version: 14, sdk: "xros1.2"},
2929
{os_version: 12, sdk: "iphoneos16.2"},
3030
{os_version: 12, sdk: "macosx13.1"},
3131
{os_version: 12, sdk: "appletvos16.1"},
32-
{os_version: 12, sdk: "visionos1.0"},
3332
{os_version: 12, sdk: "watchos9.1"},
3433
{os_version: 13, sdk: "iphoneos17.2"},
3534
{os_version: 13, sdk: "macosx14.2"},
3635
{os_version: 13, sdk: "appletvos17.2"},
3736
{os_version: 13, sdk: "watchos10.2"},
38-
{os_version: 13, sdk: "visionos1.1"}
37+
{os_version: 13, sdk: "xros1.0"},
38+
{os_version: 15, sdk: "xros2.0"}
3939
]
4040
steps:
4141
# To check the github context

Countly.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#import "CountlyContentBuilder.h"
1616
#import "CountlyFeedbacks.h"
1717
#import "Resettable.h"
18-
#if (TARGET_OS_IOS || TARGET_OS_OSX)
18+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_OSX )
1919
#import <UserNotifications/UserNotifications.h>
2020
#endif
2121

@@ -377,7 +377,7 @@ NS_ASSUME_NONNULL_BEGIN
377377

378378

379379
#pragma mark - Push Notification
380-
#if (TARGET_OS_IOS || TARGET_OS_OSX)
380+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_OSX )
381381
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
382382
/**
383383
* Shows default system dialog that asks for user's permission to display notifications.
@@ -553,7 +553,7 @@ NS_ASSUME_NONNULL_BEGIN
553553
*/
554554
- (void)recordView:(NSString *)viewName segmentation:(NSDictionary<NSString *, id> *)segmentation DEPRECATED_MSG_ATTRIBUTE("Use '[views startView/startAutoStoppedView:]' method instead!");
555555

556-
#if (TARGET_OS_IOS || TARGET_OS_TV)
556+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV )
557557
/**
558558
* Adds exception for AutoViewTracking.
559559
* @discussion @c UIViewControllers with specified title or class name will be ignored by AutoViewTracking and their appearances and disappearances will not be recorded.
@@ -594,7 +594,7 @@ NS_ASSUME_NONNULL_BEGIN
594594

595595

596596
#pragma mark - Feedbacks
597-
#if (TARGET_OS_IOS)
597+
#if (TARGET_OS_IOS || TARGET_OS_VISION )
598598
/**
599599
* Shows star-rating dialog manually and executes completion block after user's action.
600600
* @discussion Completion block has a single NSInteger parameter that indicates 1 to 5 star-rating given by user.

Countly.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ - (instancetype)init
4848
{
4949
if (self = [super init])
5050
{
51-
#if (TARGET_OS_IOS || TARGET_OS_TV)
51+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV )
5252
[NSNotificationCenter.defaultCenter addObserver:self
5353
selector:@selector(applicationDidEnterBackground:)
5454
name:UIApplicationDidEnterBackgroundNotification
@@ -197,8 +197,8 @@ - (void)startWithConfig:(CountlyConfig *)config
197197
[CountlyCommon.sharedInstance recordOrientation];
198198

199199
//NOTE: If there is no consent for sessions, location info and attribution should be sent separately, as they cannot be sent with begin_session request.
200-
201-
#if (TARGET_OS_IOS || TARGET_OS_OSX)
200+
201+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_OSX )
202202
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
203203
if ([config.features containsObject:CLYPushNotifications])
204204
{
@@ -233,8 +233,8 @@ - (void)startWithConfig:(CountlyConfig *)config
233233
CountlyCrashReporter.sharedInstance.isEnabledOnInitialConfig = YES;
234234
[CountlyCrashReporter.sharedInstance startCrashReporting];
235235
}
236-
237-
#if (TARGET_OS_IOS || TARGET_OS_TV)
236+
237+
#if (TARGET_OS_IOS || TARGET_OS_TV )
238238
if (config.enableAutomaticViewTracking || [config.features containsObject:CLYAutoViewTracking])
239239
{
240240
// Print deprecation flag for feature
@@ -614,8 +614,8 @@ - (CLYDeviceIDType)deviceIDType
614614

615615
if ([CountlyPersistency.sharedInstance retrieveIsCustomDeviceID])
616616
return CLYDeviceIDTypeCustom;
617-
618-
#if (TARGET_OS_IOS || TARGET_OS_TV)
617+
618+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV )
619619
return CLYDeviceIDTypeIDFV;
620620
#else
621621
return CLYDeviceIDTypeNSUUID;
@@ -1035,7 +1035,7 @@ - (void)cancelEvent:(NSString *)key
10351035

10361036

10371037
#pragma mark - Push Notifications
1038-
#if (TARGET_OS_IOS || TARGET_OS_OSX)
1038+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_OSX )
10391039
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
10401040

10411041
- (void)askForNotificationPermission
@@ -1188,7 +1188,7 @@ - (void)recordView:(NSString *)viewName segmentation:(NSDictionary *)segmentatio
11881188
[CountlyViewTrackingInternal.sharedInstance startAutoStoppedView:viewName segmentation:segmentation];
11891189
}
11901190

1191-
#if (TARGET_OS_IOS || TARGET_OS_TV)
1191+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV )
11921192
- (void)addExceptionForAutoViewTracking:(NSString *)exception
11931193
{
11941194
CLY_LOG_I(@"%s %@", __FUNCTION__, exception);

CountlyCommon.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void CountlyPrint(NSString *stringToPrint);
111111
- (void)startBackgroundTask;
112112
- (void)finishBackgroundTask;
113113

114-
#if (TARGET_OS_IOS || TARGET_OS_TV)
114+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV )
115115
- (UIViewController *)topViewController;
116116
- (void)tryPresentingViewController:(UIViewController *)viewController;
117117
- (void)tryPresentingViewController:(UIViewController *)viewController withCompletion:(void (^ __nullable) (void))completion;

CountlyCommon.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ @interface CountlyCommon ()
2020
}
2121
@property long long lastTimestamp;
2222

23-
#if (TARGET_OS_IOS)
23+
#if (TARGET_OS_IOS || TARGET_OS_VISION )
2424
@property (nonatomic) NSString* lastInterfaceOrientation;
2525
#endif
2626

27-
#if (TARGET_OS_IOS || TARGET_OS_TV)
27+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV )
2828
@property (nonatomic) UIBackgroundTaskIdentifier bgTask;
2929
#endif
3030
@end
@@ -244,7 +244,7 @@ - (void)recordOrientation
244244

245245
- (void)startBackgroundTask
246246
{
247-
#if (TARGET_OS_IOS || TARGET_OS_TV)
247+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV)
248248
if (self.bgTask != UIBackgroundTaskInvalid)
249249
return;
250250

@@ -258,7 +258,7 @@ - (void)startBackgroundTask
258258

259259
- (void)finishBackgroundTask
260260
{
261-
#if (TARGET_OS_IOS || TARGET_OS_TV)
261+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV)
262262
if (self.bgTask != UIBackgroundTaskInvalid && !CountlyConnectionManager.sharedInstance.connection)
263263
{
264264
[UIApplication.sharedApplication endBackgroundTask:self.bgTask];

CountlyConfig.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#import "CountlyExperimentalConfig.h"
1414
#import "CountlyContentConfig.h"
1515

16-
#if (TARGET_OS_IOS || TARGET_OS_TV)
16+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV )
1717
#import <UIKit/UIKit.h>
1818
#endif
1919

@@ -30,7 +30,7 @@ typedef void (^WidgetCallback)(WidgetState widgetState);
3030

3131
//NOTE: Countly features
3232
typedef NSString* CLYFeature NS_EXTENSIBLE_STRING_ENUM;
33-
#if (TARGET_OS_IOS)
33+
#if (TARGET_OS_IOS || TARGET_OS_VISION )
3434
#ifndef COUNTLY_EXCLUDE_PUSHNOTIFICATIONS
3535
extern CLYFeature const CLYPushNotifications;
3636
#endif
@@ -226,7 +226,7 @@ typedef enum : NSUInteger
226226

227227
#pragma mark -
228228

229-
#if (TARGET_OS_IOS || TARGET_OS_TV)
229+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV)
230230
/**
231231
* For enabling automatic view tacking.
232232
* @discussion If set, views will automatically track.

CountlyConfig.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ - (void)enableAPMInternal:(BOOL)enableAPM;
1717
@implementation CountlyConfig
1818

1919
//NOTE: Countly features
20-
#if (TARGET_OS_IOS)
20+
#if (TARGET_OS_IOS || TARGET_OS_VISION)
2121
CLYFeature const CLYPushNotifications = @"CLYPushNotifications";
2222
CLYFeature const CLYCrashReporting = @"CLYCrashReporting";
2323
// CLYAutoViewTracking is deprecated, Use 'config.enableAutomaticViewTracking' instead

CountlyConnectionManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ - (NSString *)attributionQueryString
830830

831831
- (NSMutableData *)pictureUploadDataForQueryString:(NSString *)queryString
832832
{
833-
#if (TARGET_OS_IOS)
833+
#if (TARGET_OS_IOS || TARGET_OS_VISION)
834834
NSString* localPicturePath = nil;
835835

836836
NSString* userDetails = [queryString cly_valueForQueryStringKey:kCountlyQSKeyUserDetails];

CountlyConsentManager.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ - (void)setConsentForPushNotifications:(BOOL)consentForPushNotifications
332332
{
333333
_consentForPushNotifications = consentForPushNotifications;
334334

335-
#if (TARGET_OS_IOS || TARGET_OS_OSX)
335+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_OSX)
336336
if (consentForPushNotifications)
337337
{
338338
CLY_LOG_D(@"Consent for PushNotifications is given.");
@@ -375,7 +375,7 @@ - (void)setConsentForViewTracking:(BOOL)consentForViewTracking
375375
{
376376
_consentForViewTracking = consentForViewTracking;
377377

378-
#if (TARGET_OS_IOS || TARGET_OS_TV)
378+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV)
379379
if (consentForViewTracking)
380380
{
381381
CLY_LOG_D(@"Consent for ViewTracking is given.");
@@ -413,7 +413,7 @@ - (void)setConsentForPerformanceMonitoring:(BOOL)consentForPerformanceMonitoring
413413
{
414414
_consentForPerformanceMonitoring = consentForPerformanceMonitoring;
415415

416-
#if (TARGET_OS_IOS)
416+
#if (TARGET_OS_IOS || TARGET_OS_VISION)
417417
if (consentForPerformanceMonitoring)
418418
{
419419
CLY_LOG_D(@"Consent for PerformanceMonitoring is given.");

CountlyCrashReporter.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ - (void)startCrashReporting
108108

109109
NSSetUncaughtExceptionHandler(&CountlyUncaughtExceptionHandler);
110110

111-
#if (TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_OSX)
111+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV || TARGET_OS_OSX)
112112
signal(SIGABRT, CountlySignalHandler);
113113
signal(SIGILL, CountlySignalHandler);
114114
signal(SIGSEGV, CountlySignalHandler);
@@ -127,7 +127,7 @@ - (void)stopCrashReporting
127127

128128
NSSetUncaughtExceptionHandler(NULL);
129129

130-
#if (TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_OSX)
130+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV || TARGET_OS_OSX)
131131
signal(SIGABRT, SIG_DFL);
132132
signal(SIGILL, SIG_DFL);
133133
signal(SIGSEGV, SIG_DFL);

CountlyDeviceInfo.m

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ - (instancetype)init
6565
#endif
6666
#endif
6767

68-
#if (TARGET_OS_IOS || TARGET_OS_TV)
68+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV)
6969
self.isInBackground = (UIApplication.sharedApplication.applicationState == UIApplicationStateBackground);
7070

7171
[NSNotificationCenter.defaultCenter addObserver:self
@@ -107,7 +107,7 @@ - (NSString *)ensafeDeviceID:(NSString *)deviceID
107107
if (deviceID.length)
108108
return deviceID;
109109

110-
#if (TARGET_OS_IOS || TARGET_OS_TV)
110+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV)
111111
return UIDevice.currentDevice.identifierForVendor.UUIDString;
112112
#else
113113
NSString* UUID = [CountlyPersistency.sharedInstance retrieveNSUUID];
@@ -182,6 +182,8 @@ + (NSString *)deviceType
182182
return @"smarttv";
183183
#elif (TARGET_OS_OSX)
184184
return @"desktop";
185+
#elif (TARGET_OS_VISION)
186+
return @"vr";
185187
#endif
186188

187189
return nil;
@@ -218,14 +220,16 @@ + (NSString *)osName
218220
return @"tvOS";
219221
#elif (TARGET_OS_OSX)
220222
return @"macOS";
223+
#elif (TARGET_OS_VISION)
224+
return @"visionOS";
221225
#endif
222226

223227
return nil;
224228
}
225229

226230
+ (NSString *)osVersion
227231
{
228-
#if (TARGET_OS_IOS || TARGET_OS_TV)
232+
#if (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV)
229233
return UIDevice.currentDevice.systemVersion;
230234
#elif (TARGET_OS_WATCH)
231235
return WKInterfaceDevice.currentDevice.systemVersion;
@@ -260,34 +264,35 @@ + (NSString *)carrier
260264

261265
+ (NSString *)resolution
262266
{
267+
CGRect bounds;
268+
CGFloat scale;
263269
#if (TARGET_OS_IOS || TARGET_OS_TV)
264-
CGRect bounds = UIScreen.mainScreen.bounds;
265-
CGFloat scale = UIScreen.mainScreen.scale;
270+
bounds = UIScreen.mainScreen.bounds;
271+
scale = UIScreen.mainScreen.scale;
266272
#elif (TARGET_OS_WATCH)
267-
CGRect bounds = WKInterfaceDevice.currentDevice.screenBounds;
268-
CGFloat scale = WKInterfaceDevice.currentDevice.screenScale;
273+
bounds = WKInterfaceDevice.currentDevice.screenBounds;
274+
scale = WKInterfaceDevice.currentDevice.screenScale;
269275
#elif (TARGET_OS_OSX)
270-
NSRect bounds = NSScreen.mainScreen.frame;
271-
CGFloat scale = NSScreen.mainScreen.backingScaleFactor;
276+
bounds = NSScreen.mainScreen.frame;
277+
scale = NSScreen.mainScreen.backingScaleFactor;
272278
#else
273279
return nil;
274280
#endif
275-
276281
return [NSString stringWithFormat:@"%gx%g", bounds.size.width * scale, bounds.size.height * scale];
277282
}
278283

279284
+ (NSString *)density
280285
{
286+
CGFloat scale;
281287
#if (TARGET_OS_IOS || TARGET_OS_TV)
282-
CGFloat scale = UIScreen.mainScreen.scale;
288+
scale = UIScreen.mainScreen.scale;
283289
#elif (TARGET_OS_WATCH)
284-
CGFloat scale = WKInterfaceDevice.currentDevice.screenScale;
290+
scale = WKInterfaceDevice.currentDevice.screenScale;
285291
#elif (TARGET_OS_OSX)
286-
CGFloat scale = NSScreen.mainScreen.backingScaleFactor;
292+
scale = NSScreen.mainScreen.backingScaleFactor;
287293
#else
288294
return nil;
289295
#endif
290-
291296
return [NSString stringWithFormat:@"@%dx", (int)scale];
292297
}
293298

@@ -409,7 +414,7 @@ + (unsigned long long)totalDisk
409414
// If it is not possible to retrieve a valid value then it will return a -1.
410415
+ (NSInteger)batteryLevel
411416
{
412-
#if (TARGET_OS_IOS)
417+
#if (TARGET_OS_IOS || TARGET_OS_VISION)
413418
// If battey state is "unknown" that means that battery monitoring is not enabled.
414419
// In that case we will not able to retrieve a battery level.
415420
if (UIDevice.currentDevice.batteryState == UIDeviceBatteryStateUnknown)

CountlyNotificationService.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#import <Foundation/Foundation.h>
88

9-
#if (TARGET_OS_IOS)
9+
#if (TARGET_OS_IOS || TARGET_OS_VISION)
1010
#import <UserNotifications/UserNotifications.h>
1111
#endif
1212

@@ -24,7 +24,7 @@ extern NSString* const kCountlyPNKeyActionButtonTitle;
2424
extern NSString* const kCountlyPNKeyActionButtonURL;
2525

2626
@interface CountlyNotificationService : NSObject
27-
#if (TARGET_OS_IOS)
27+
#if (TARGET_OS_IOS || TARGET_OS_VISION)
2828
+ (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent *))contentHandler API_AVAILABLE(ios(10.0));
2929
#endif
3030

CountlyNotificationService.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
NSString* const kCountlyPNKeyActionButtonURL = @"l";
2626

2727
@implementation CountlyNotificationService
28-
#if (TARGET_OS_IOS)
28+
#if (TARGET_OS_IOS || TARGET_OS_VISION)
2929
+ (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent *))contentHandler
3030
{
3131
COUNTLY_EXT_LOG(@"didReceiveNotificationRequest:withContentHandler:");

CountlyPerformanceMonitoring.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ - (void)startPerformanceMonitoring
8484
#if (TARGET_OS_OSX)
8585
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:nil];
8686
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(applicationWillResignActive:) name:NSApplicationWillResignActiveNotification object:nil];
87-
#elif (TARGET_OS_IOS || TARGET_OS_TV)
87+
#elif (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV)
8888
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
8989
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
9090
#endif
@@ -100,7 +100,7 @@ - (void)stopPerformanceMonitoring
100100
#if (TARGET_OS_OSX)
101101
[NSNotificationCenter.defaultCenter removeObserver:self name:NSApplicationDidBecomeActiveNotification object:nil];
102102
[NSNotificationCenter.defaultCenter removeObserver:self name:NSApplicationWillResignActiveNotification object:nil];
103-
#elif (TARGET_OS_IOS || TARGET_OS_TV)
103+
#elif (TARGET_OS_IOS || TARGET_OS_VISION || TARGET_OS_TV)
104104
[NSNotificationCenter.defaultCenter removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
105105
[NSNotificationCenter.defaultCenter removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
106106
#endif

0 commit comments

Comments
 (0)