Skip to content

Commit

Permalink
feat: watchOS/tvOS/visionOS support (#3)
Browse files Browse the repository at this point in the history
* feat: watchOS/tvOS/visionOS support

* ci: update ci

* feat: release 1.2.0

* ci: update ci

* ci: update ci

* Revert "ci: update ci"

This reverts commit 7d05d50.

* ci: update ci

* ci: update ci

* ci: update ci
  • Loading branch information
YoloMao authored Feb 1, 2024
1 parent 8b1ab92 commit 1a3e637
Show file tree
Hide file tree
Showing 17 changed files with 465 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cocoapods.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Cocoapods
name: Cocoapods Trunk Push
on:
release:
types: [published]
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/pod_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Pod Lint

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: macos-13

steps:
- name: Force Xcode 15
run: sudo xcode-select -switch /Applications/Xcode_15.2.app

- name: Checkout Repo
uses: actions/checkout@v4

- name: Pod Lint
run: pod lib lint GrowingUtils.podspec --allow-warnings --verbose
108 changes: 108 additions & 0 deletions .github/workflows/spm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: SPM

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
build-iOS:
runs-on: macos-13

steps:
- name: Force Xcode 15
run: sudo xcode-select -switch /Applications/Xcode_15.2.app

- name: Checkout Repo
uses: actions/checkout@v4

- name: Build
run: |
set -euo pipefail
xcodebuild build -scheme GrowingUtils-Package -destination 'platform=iOS Simulator,name=iPhone 15 Pro Max' \
| xcbeautify --renderer github-actions
build-catalyst:
runs-on: macos-13

steps:
- name: Force Xcode 15
run: sudo xcode-select -switch /Applications/Xcode_15.2.app

- name: Checkout Repo
uses: actions/checkout@v4

- name: Build
run: |
set -euo pipefail
xcodebuild build -scheme GrowingUtils-Package -destination 'platform=macOS,variant=Mac Catalyst' \
| xcbeautify --renderer github-actions
build-macOS:
runs-on: macos-13

steps:
- name: Force Xcode 15
run: sudo xcode-select -switch /Applications/Xcode_15.2.app

- name: Checkout Repo
uses: actions/checkout@v4

- name: Build
run: |
set -euo pipefail
xcodebuild build -scheme GrowingUtils-Package -destination 'platform=macOS' \
| xcbeautify --renderer github-actions
build-watchOS:
runs-on: macos-13

steps:
- name: Force Xcode 15
run: sudo xcode-select -switch /Applications/Xcode_15.2.app

- name: Checkout Repo
uses: actions/checkout@v4

- name: Build
run: |
set -euo pipefail
xcodebuild build -scheme GrowingUtils-Package -destination 'platform=watchOS Simulator,name=Apple Watch Ultra 2 (49mm)' \
| xcbeautify --renderer github-actions
build-tvOS:
runs-on: macos-13

steps:
- name: Force Xcode 15
run: sudo xcode-select -switch /Applications/Xcode_15.2.app

- name: Checkout Repo
uses: actions/checkout@v4

- name: Build
run: |
set -euo pipefail
xcodebuild build -scheme GrowingUtils-Package -destination 'platform=tvOS Simulator,name=Apple TV' \
| xcbeautify --renderer github-actions
build-visionOS:
runs-on: macos-14

steps:
- name: Force Xcode 15
run: sudo xcode-select -switch /Applications/Xcode_15.2.app

- name: Checkout Repo
uses: actions/checkout@v4

- name: Build
run: |
set -euo pipefail
xcodebuild build -scheme GrowingUtils-Package -destination 'platform=visionOS Simulator,name=Apple Vision Pro' \
| xcbeautify --renderer github-actions
4 changes: 3 additions & 1 deletion GrowingUtils.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'GrowingUtils'
s.version = '1.1.0'
s.version = '1.2.0'
s.summary = 'iOS SDK of GrowingIO.'
s.description = <<-DESC
GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和行为数据等。目前支持代码埋点、无埋点、可视化圈选、热图等功能。
Expand All @@ -11,6 +11,8 @@ GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和
s.source = { :git => 'https://github.com/growingio/growingio-sdk-ios-utilities.git', :tag => s.version.to_s }
s.ios.deployment_target = '10.0'
s.osx.deployment_target = '10.12'
s.tvos.deployment_target = '10.0'
s.watchos.deployment_target = '7.0'
s.requires_arc = true
s.default_subspec = "TrackerCore"

Expand Down
8 changes: 7 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ import PackageDescription

let package = Package(
name: "GrowingUtils",
platforms: [.iOS(.v10), .macCatalyst(.v13), .macOS(.v10_12)],
platforms: [
.iOS(.v10),
.macCatalyst(.v13),
.macOS(.v10_12),
.tvOS(.v10),
.watchOS(.v7)
],
products: [
.library(
name: "GrowingUtilsTrackerCore",
Expand Down
77 changes: 77 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// swift-tools-version:5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

//
// Package.swift
// GrowingAnalytics
//
// Created by YoloMao on 2024/2/1.
// Copyright (C) 2024 Beijing Yishu Technology Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import PackageDescription

let package = Package(
name: "GrowingUtils",
platforms: [
.iOS(.v12),
.macCatalyst(.v13),
.macOS(.v10_14),
.tvOS(.v12),
.watchOS(.v7),
.visionOS(.v1)
],
products: [
.library(
name: "GrowingUtilsTrackerCore",
targets: ["GrowingUtilsTrackerCore_Wrapper"]
),
.library(
name: "GrowingUtilsAutotrackerCore",
targets: ["GrowingUtilsAutotrackerCore_Wrapper"]
),
],
dependencies: [],
targets: [
.target(
name: "GrowingUtilsTrackerCore_Wrapper",
dependencies: [.target(name: "GrowingUtilsTrackerCore",
condition: .when(platforms: [.iOS, .macCatalyst, .macOS]))],
path: "SwiftPM-Wrap/TrackerCore-Wrapper"
),
.target(
name: "GrowingUtilsAutotrackerCore_Wrapper",
dependencies: [.target(name: "GrowingUtilsAutotrackerCore",
condition: .when(platforms: [.iOS, .macCatalyst]))],
path: "SwiftPM-Wrap/AutotrackerCore-Wrapper"
),
.target(
name: "GrowingUtilsTrackerCore",
dependencies: [],
path: "Sources/TrackerCore",
resources: [.copy("Resources/PrivacyInfo.xcprivacy")],
cSettings: [
.headerSearchPath("include"),
]
),
.target(
name: "GrowingUtilsAutotrackerCore",
dependencies: ["GrowingUtilsTrackerCore"],
path: "Sources/AutotrackerCore",
cSettings: [
.headerSearchPath("include"),
]
),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#import "GrowingTargetConditionals.h"

#if Growing_USE_UIKIT
#import "GrowingULViewControllerLifecycle.h"
#import "GrowingULTimeUtil.h"
#import "GrowingULSwizzle.h"
Expand Down Expand Up @@ -266,3 +269,4 @@ - (void)dispatchViewControllerDidDisappear:(UIViewController *)controller {
}

@end
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "GrowingTargetConditionals.h"

#if Growing_USE_UIKIT
@protocol GrowingULViewControllerLifecycleDelegate <NSObject>

@optional
Expand Down Expand Up @@ -56,3 +56,4 @@
- (void)removeViewControllerLifecycleDelegate:(id<GrowingULViewControllerLifecycleDelegate>)delegate;

@end
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if __has_include(<UIKit/UIKit.h>)
#import "GrowingTargetConditionals.h"

#if Growing_USE_UIKIT
#import "UIApplication+GrowingUtilsTrackerCore.h"
#import "UIViewController+GrowingUtilsTrackerCore.h"
#import "GrowingULApplication.h"
Expand All @@ -29,7 +31,11 @@ - (nullable UIWindow *)growingul_keyWindow {
return nil;
}

if (@available(iOS 13.0, *)) {
#if Growing_OS_VISION
if (1) { // if (@available(visionOS 1.0, *)) {
#else
if (@available(iOS 13.0, macCatalyst 13.1, tvOS 13.0, *)) {
#endif
for (UIScene *scene in self.connectedScenes) {
if (scene.activationState != UISceneActivationStateForegroundActive) {
continue;
Expand Down Expand Up @@ -71,11 +77,15 @@ - (nullable UIViewController *)growingul_topViewController {
}

- (CGFloat)growingul_statusBarHeight {
if (@available(iOS 13.0, *)) {
return self.growingul_keyWindow.windowScene.statusBarManager.statusBarFrame.size.height;
CGFloat statusBarHeight = 0.0f;
#if Growing_OS_IOS || Growing_OS_MACCATALYST
if (@available(iOS 13.0, macCatalyst 13.1, *)) {
statusBarHeight = self.growingul_keyWindow.windowScene.statusBarManager.statusBarFrame.size.height;
} else {
statusBarHeight = self.statusBarFrame.size.height;

Check warning on line 85 in Sources/TrackerCore/Category/UIApplication+GrowingUtilsTrackerCore.m

View workflow job for this annotation

GitHub Actions / build-catalyst

'statusBarFrame' is deprecated: first deprecated in macCatalyst 13.1 - Use the statusBarManager property of the window scene instead. [-Wdeprecated-declarations]
}
return self.statusBarFrame.size.height;
#endif
return statusBarHeight;
}

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if __has_include(<UIKit/UIKit.h>)
#import "GrowingTargetConditionals.h"

#if Growing_USE_UIKIT
#import "UIViewController+GrowingUtilsTrackerCore.h"

@implementation UIViewController (GrowingUtilsTrackerCore)
Expand Down
22 changes: 12 additions & 10 deletions Sources/TrackerCore/Extension/GrowingULApplication.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ @implementation GrowingULApplication
+ (nullable id)sharedApplication {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
#if TARGET_OS_OSX
Class class = NSClassFromString(@"NSApplication");
#elif TARGET_OS_IOS || TARGET_OS_MACCATALYST || TARGET_OS_TV
Class class = NSClassFromString(@"UIApplication");
#elif TARGET_OS_WATCH
Class class = NSClassFromString(@"WKApplication");
Class class;
#if Growing_USE_APPKIT
class = NSClassFromString(@"NSApplication");
#elif Growing_USE_UIKIT
class = NSClassFromString(@"UIApplication");
#elif Growing_USE_WATCHKIT
class = NSClassFromString(@"WKApplication");
#endif

SEL selector = NSSelectorFromString(@"sharedApplication");
if(!class || ![class respondsToSelector:selector]) {
return nil;
Expand All @@ -40,10 +42,10 @@ + (nullable id)sharedApplication {
}

+ (BOOL)isAppExtension {
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH
return [[[NSBundle mainBundle] bundlePath] hasSuffix:@".appex"];
#elif TARGET_OS_OSX
return NO;
#if Growing_OS_IOS || Growing_OS_TV || Growing_OS_WATCH
return [[[NSBundle mainBundle] bundlePath] hasSuffix:@".appex"];
#else
return NO;
#endif
}

Expand Down
Loading

0 comments on commit 1a3e637

Please sign in to comment.