Skip to content

Commit 5f793b8

Browse files
committed
Lets let targets stay in git, so we can compare
1 parent e752bcd commit 5f793b8

File tree

7 files changed

+320
-129
lines changed

7 files changed

+320
-129
lines changed

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ PODS:
11991199
- React-logger (= 0.74.5)
12001200
- React-perflogger (= 0.74.5)
12011201
- React-utils (= 0.74.5)
1202-
- ReactNativeDeviceActivity (0.1.0):
1202+
- ReactNativeDeviceActivity (0.0.18):
12031203
- ExpoModulesCore
12041204
- SocketRocket (0.7.0)
12051205
- Yoga (0.0.0)
@@ -1462,7 +1462,7 @@ SPEC CHECKSUMS:
14621462
React-runtimescheduler: cfbe85c3510c541ec6dc815c7729b41304b67961
14631463
React-utils: f242eb7e7889419d979ca0e1c02ccc0ea6e43b29
14641464
ReactCommon: f7da14a8827b72704169a48c929bcde802698361
1465-
ReactNativeDeviceActivity: a0a6f93aa4e6aff812da277daddbc54384d2f671
1465+
ReactNativeDeviceActivity: 5f6084298a381cec8516730a2070c77e1ef855d9
14661466
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
14671467
Yoga: 2246eea72aaf1b816a68a35e6e4b74563653ae09
14681468

example/ios/reactnativedeviceactivityexample.xcodeproj/project.pbxproj

Lines changed: 127 additions & 127 deletions
Large diffs are not rendered by default.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.developer.family-controls</key>
6+
<true/>
7+
<key>com.apple.security.application-groups</key>
8+
<array>
9+
<string>group.ActivityMonitor</string>
10+
</array>
11+
</dict>
12+
</plist>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
//
2+
// DeviceActivityMonitorExtension.swift
3+
// ActivityMonitorExtension
4+
//
5+
// Created by Robert Herber on 2023-07-05.
6+
//
7+
8+
import DeviceActivity
9+
import ManagedSettings
10+
import Foundation
11+
import os
12+
13+
@available(iOS 14.0, *)
14+
let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "react-native-device-activity")
15+
16+
// Optionally override any of the functions below.
17+
// Make sure that your class name matches the NSExtensionPrincipalClass in your Info.plist.
18+
@available(iOS 15.0, *)
19+
class DeviceActivityMonitorExtension: DeviceActivityMonitor {
20+
let notificationCenter = CFNotificationCenterGetDarwinNotifyCenter()
21+
let userDefaults = UserDefaults(suiteName: "group.ActivityMonitor")
22+
23+
func sendNotification(name: String){
24+
let notificationName = CFNotificationName(name as CFString)
25+
26+
CFNotificationCenterPostNotification(notificationCenter, notificationName, nil, nil, false)
27+
}
28+
29+
func persistToUserDefaults(activityName: String, callbackName: String, eventName: String? = nil){
30+
let now = (Date().timeIntervalSince1970 * 1000).rounded()
31+
let fullEventName = eventName == nil
32+
? "DeviceActivityMonitorExtension#\(activityName)#\(callbackName)"
33+
: "DeviceActivityMonitorExtension#\(activityName)#\(callbackName)#\(eventName!)"
34+
userDefaults?.set(now, forKey: fullEventName)
35+
}
36+
37+
override func intervalDidStart(for activity: DeviceActivityName) {
38+
super.intervalDidStart(for: activity)
39+
logger.log("intervalDidStart")
40+
41+
self.persistToUserDefaults(
42+
activityName: activity.rawValue,
43+
callbackName: "intervalDidStart"
44+
)
45+
46+
self.sendNotification(name: "intervalDidStart")
47+
}
48+
49+
override func intervalDidEnd(for activity: DeviceActivityName) {
50+
super.intervalDidEnd(for: activity)
51+
logger.log("intervalDidEnd")
52+
53+
self.persistToUserDefaults(
54+
activityName: activity.rawValue,
55+
callbackName: "intervalDidEnd"
56+
)
57+
58+
self.sendNotification(name: "intervalDidEnd")
59+
}
60+
61+
override func eventDidReachThreshold(_ event: DeviceActivityEvent.Name, activity: DeviceActivityName) {
62+
super.eventDidReachThreshold(event, activity: activity)
63+
logger.log("eventDidReachThreshold: \(event.rawValue, privacy: .public)")
64+
65+
self.persistToUserDefaults(
66+
activityName: activity.rawValue,
67+
callbackName: "eventDidReachThreshold",
68+
eventName: event.rawValue
69+
)
70+
71+
self.sendNotification(name: "eventDidReachThreshold")
72+
}
73+
74+
override func intervalWillStartWarning(for activity: DeviceActivityName) {
75+
super.intervalWillStartWarning(for: activity)
76+
logger.log("intervalWillStartWarning")
77+
78+
self.persistToUserDefaults(
79+
activityName: activity.rawValue,
80+
callbackName: "intervalWillStartWarning"
81+
)
82+
83+
self.sendNotification(name: "intervalWillStartWarning")
84+
}
85+
86+
override func intervalWillEndWarning(for activity: DeviceActivityName) {
87+
super.intervalWillEndWarning(for: activity)
88+
logger.log("intervalWillEndWarning")
89+
90+
self.persistToUserDefaults(
91+
activityName: activity.rawValue,
92+
callbackName: "intervalWillEndWarning"
93+
)
94+
95+
self.sendNotification(name: "intervalWillEndWarning")
96+
}
97+
98+
override func eventWillReachThresholdWarning(_ event: DeviceActivityEvent.Name, activity: DeviceActivityName) {
99+
super.eventWillReachThresholdWarning(event, activity: activity)
100+
logger.log("eventWillReachThresholdWarning: \(event.rawValue, privacy: .public)")
101+
102+
self.persistToUserDefaults(
103+
activityName: activity.rawValue,
104+
callbackName: "eventWillReachThresholdWarning",
105+
eventName: event.rawValue
106+
)
107+
108+
self.sendNotification(name: "eventWillReachThresholdWarning")
109+
}
110+
111+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>NSExtension</key>
6+
<dict>
7+
<key>NSExtensionPointIdentifier</key>
8+
<string>com.apple.deviceactivity.monitor-extension</string>
9+
<key>NSExtensionPrincipalClass</key>
10+
<string>$(PRODUCT_MODULE_NAME).DeviceActivityMonitorExtension</string>
11+
</dict>
12+
</dict>
13+
</plist>
14+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>NSPrivacyAccessedAPITypes</key>
6+
<array>
7+
<dict>
8+
<key>NSPrivacyAccessedAPIType</key>
9+
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
10+
<key>NSPrivacyAccessedAPITypeReasons</key>
11+
<array>
12+
<string>CA92.1</string>
13+
</array>
14+
</dict>
15+
<dict>
16+
<key>NSPrivacyAccessedAPIType</key>
17+
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
18+
<key>NSPrivacyAccessedAPITypeReasons</key>
19+
<array>
20+
<string>0A2A.1</string>
21+
<string>3B52.1</string>
22+
<string>C617.1</string>
23+
</array>
24+
</dict>
25+
<dict>
26+
<key>NSPrivacyAccessedAPIType</key>
27+
<string>NSPrivacyAccessedAPICategoryDiskSpace</string>
28+
<key>NSPrivacyAccessedAPITypeReasons</key>
29+
<array>
30+
<string>E174.1</string>
31+
<string>85F4.1</string>
32+
</array>
33+
</dict>
34+
<dict>
35+
<key>NSPrivacyAccessedAPIType</key>
36+
<string>NSPrivacyAccessedAPICategorySystemBootTime</string>
37+
<key>NSPrivacyAccessedAPITypeReasons</key>
38+
<array>
39+
<string>35F9.1</string>
40+
</array>
41+
</dict>
42+
</array>
43+
<key>NSPrivacyCollectedDataTypes</key>
44+
<array/>
45+
<key>NSPrivacyTracking</key>
46+
<false/>
47+
</dict>
48+
</plist>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('expo-apple-targets/target-plugin/config').Config} */
2+
const config = {
3+
type: "device-activity-monitor",
4+
};
5+
6+
module.exports = config;

0 commit comments

Comments
 (0)