-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
275 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// Example-Bridging-Header.h | ||
// GrowingAnalytics | ||
// | ||
// Created by YoloMao on 2023/8/21. | ||
// Copyright (C) 2023 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. | ||
|
||
#ifndef Example_Bridging_Header_h | ||
#define Example_Bridging_Header_h | ||
|
||
|
||
#endif /* Example_Bridging_Header_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// GIOSwiftUIContentViewController.h | ||
// GrowingAnalytics | ||
// | ||
// Created by YoloMao on 2023/8/21. | ||
// Copyright (C) 2023 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 <UIKit/UIKit.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface GIOSwiftUIContentViewController : UIViewController | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// GIOSwiftUIContentViewController.m | ||
// GrowingAnalytics | ||
// | ||
// Created by YoloMao on 2023/8/21. | ||
// Copyright (C) 2023 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 "GIOSwiftUIContentViewController.h" | ||
#import "Example-Swift.h" | ||
|
||
@interface GIOSwiftUIContentViewController () | ||
|
||
@end | ||
|
||
@implementation GIOSwiftUIContentViewController | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
|
||
if (@available(iOS 13.0, *)) { | ||
UIViewController *controller = [SwiftUIViewWrapper viewController]; | ||
UIView *view = controller.view; | ||
view.frame = self.view.frame; | ||
[self.view addSubview:view]; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// SwiftUIView.swift | ||
// GrowingAnalytics | ||
// | ||
// Created by YoloMao on 2023/8/21. | ||
// Copyright (C) 2023 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. | ||
|
||
// 参考:https://github.com/firebase/firebase-ios-sdk/tree/master/FirebaseAnalyticsSwift | ||
#if canImport(SwiftUI) | ||
import SwiftUI | ||
import GrowingAnalytics | ||
|
||
@available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, *) | ||
@objc class SwiftUIViewWrapper: NSObject { | ||
@objc static func viewController() -> UIViewController { | ||
UIHostingController(rootView: SwiftUIView()) | ||
} | ||
} | ||
|
||
@available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, *) | ||
struct SwiftUIView: View { | ||
var body: some View { | ||
VStack { | ||
Text("Hello, World!") | ||
.padding() | ||
Button("TrackCustomEvent") { | ||
GrowingAutotracker.sharedInstance().trackCustomEvent("Custom", withAttributes: ["key": "value"]) | ||
} | ||
} | ||
.growingTrackView("SwiftUI-View-OnAppear", attributes: ["key": "value"]) | ||
// .onAppear { | ||
// GrowingAutotracker.sharedInstance().trackCustomEvent("SwiftUI-View-OnAppear", withAttributes: ["key": "value"]) | ||
// } | ||
} | ||
} | ||
|
||
@available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, *) | ||
extension View { | ||
func growingTrackView(_ eventName: String, attributes: [String: String]? = nil) -> some View { | ||
onAppear { | ||
if let attributes = attributes { | ||
GrowingAutotracker.sharedInstance().trackCustomEvent(eventName, withAttributes: attributes) | ||
} else { | ||
GrowingAutotracker.sharedInstance().trackCustomEvent(eventName) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, *) | ||
struct SwiftUIView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
SwiftUIView() | ||
} | ||
} | ||
#endif |
Oops, something went wrong.