Skip to content

Commit bfc97ac

Browse files
committed
ios tweaks
1 parent d65734a commit bfc97ac

26 files changed

+3189
-60
lines changed

examples/build_ios.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# iOS Setup (React Native): Push Notifications + Live Activities
22

3-
Configure the React Native demo iOS project for OneSignal push notifications and live activities. All paths below are relative to `examples/demo/ios/` unless stated otherwise.
3+
Configure the React Native demo iOS project for OneSignal push notifications and live activities. Set the iOS app bundle id to `com.onesignal.example` before completing the steps below. All paths below are relative to `examples/demo/ios/` unless stated otherwise.
44

55
---
66

@@ -12,12 +12,10 @@ Add two extension targets after the `demo` target block:
1212

1313
```ruby
1414
target 'OneSignalNotificationServiceExtension' do
15-
use_frameworks! :linkage => :static
1615
pod 'OneSignalXCFramework', '>= 5.0.0', '< 6.0'
1716
end
1817

1918
target 'OneSignalWidgetExtension' do
20-
use_frameworks! :linkage => :static
2119
pod 'OneSignalXCFramework', '>= 5.0.0', '< 6.0'
2220
end
2321
```
@@ -49,13 +47,15 @@ This enables push notifications (`aps-environment`) and an App Group shared with
4947

5048
### Info.plist
5149

52-
In `demo/Info.plist`, add `UIBackgroundModes` inside the top-level `<dict>`:
50+
In `demo/Info.plist`, add `UIBackgroundModes` and `NSSupportsLiveActivities` inside the top-level `<dict>`:
5351

5452
```xml
5553
<key>UIBackgroundModes</key>
5654
<array>
5755
<string>remote-notification</string>
5856
</array>
57+
<key>NSSupportsLiveActivities</key>
58+
<true/>
5959
```
6060

6161
---
@@ -157,7 +157,7 @@ Note: the on-disk folder is `OneSignalWidget` but the Xcode target name is `OneS
157157

158158
### Info.plist
159159

160-
Same standard `CFBundle*` keys as the NSE, plus `NSSupportsLiveActivities`.
160+
Same standard `CFBundle*` keys as the NSE.
161161

162162
```xml
163163
<?xml version="1.0" encoding="UTF-8"?>
@@ -180,8 +180,6 @@ Same standard `CFBundle*` keys as the NSE, plus `NSSupportsLiveActivities`.
180180
<string>$(MARKETING_VERSION)</string>
181181
<key>CFBundleVersion</key>
182182
<string>$(CURRENT_PROJECT_VERSION)</string>
183-
<key>NSSupportsLiveActivities</key>
184-
<true/>
185183
<key>NSExtension</key>
186184
<dict>
187185
<key>NSExtensionPointIdentifier</key>
@@ -273,7 +271,7 @@ The `project.pbxproj` needs native target entries for both extensions. These are
273271
**OneSignalNotificationServiceExtension target** (`com.apple.product-type.app-extension`):
274272

275273
- Sources, Frameworks, Resources build phases
276-
- `PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.OneSignalNotificationServiceExtension` (must be prefixed with the parent app bundle ID)
274+
- `PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.OneSignalNotificationServiceExtensionRN` (must be prefixed with the parent app bundle ID)
277275
- `CODE_SIGN_ENTITLEMENTS = OneSignalNotificationServiceExtension/OneSignalNotificationServiceExtension.entitlements`
278276
- `INFOPLIST_FILE = OneSignalNotificationServiceExtension/Info.plist`
279277
- `SKIP_INSTALL = YES`, `SWIFT_VERSION = 5.0`, `IPHONEOS_DEPLOYMENT_TARGET = 13.0`
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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>CFBundleDisplayName</key>
6+
<string>OneSignalNotificationServiceExtension</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>$(MARKETING_VERSION)</string>
19+
<key>CFBundleVersion</key>
20+
<string>$(CURRENT_PROJECT_VERSION)</string>
21+
<key>NSExtension</key>
22+
<dict>
23+
<key>NSExtensionPointIdentifier</key>
24+
<string>com.apple.usernotifications.service</string>
25+
<key>NSExtensionPrincipalClass</key>
26+
<string>$(PRODUCT_MODULE_NAME).NotificationService</string>
27+
</dict>
28+
<key>RCTNewArchEnabled</key>
29+
<true/>
30+
</dict>
31+
</plist>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import UserNotifications
2+
import OneSignalExtension
3+
4+
class NotificationService: UNNotificationServiceExtension {
5+
var contentHandler: ((UNNotificationContent) -> Void)?
6+
var receivedRequest: UNNotificationRequest!
7+
var bestAttemptContent: UNMutableNotificationContent?
8+
9+
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
10+
self.receivedRequest = request
11+
self.contentHandler = contentHandler
12+
self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
13+
14+
if let bestAttemptContent = bestAttemptContent {
15+
OneSignalExtension.didReceiveNotificationExtensionRequest(self.receivedRequest, with: bestAttemptContent, withContentHandler: self.contentHandler)
16+
}
17+
}
18+
19+
override func serviceExtensionTimeWillExpire() {
20+
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
21+
OneSignalExtension.serviceExtensionTimeWillExpireRequest(self.receivedRequest, with: self.bestAttemptContent)
22+
contentHandler(bestAttemptContent)
23+
}
24+
}
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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.security.application-groups</key>
6+
<array>
7+
<string>group.com.onesignal.example.onesignal</string>
8+
</array>
9+
</dict>
10+
</plist>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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>CFBundleDisplayName</key>
6+
<string>OneSignalWidgetExtension</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>$(MARKETING_VERSION)</string>
19+
<key>CFBundleVersion</key>
20+
<string>$(CURRENT_PROJECT_VERSION)</string>
21+
<key>NSExtension</key>
22+
<dict>
23+
<key>NSExtensionPointIdentifier</key>
24+
<string>com.apple.widgetkit-extension</string>
25+
</dict>
26+
<key>RCTNewArchEnabled</key>
27+
<true/>
28+
</dict>
29+
</plist>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import WidgetKit
2+
import SwiftUI
3+
4+
@main
5+
struct OneSignalWidgetBundle: WidgetBundle {
6+
var body: some Widget {
7+
OneSignalWidgetLiveActivity()
8+
}
9+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import ActivityKit
2+
import WidgetKit
3+
import SwiftUI
4+
import OneSignalLiveActivities
5+
6+
struct OneSignalWidgetAttributes: OneSignalLiveActivityAttributes {
7+
public struct ContentState: OneSignalLiveActivityContentState {
8+
var emoji: String
9+
var onesignal: OneSignalLiveActivityContentStateData?
10+
}
11+
var name: String
12+
var onesignal: OneSignalLiveActivityAttributeData
13+
}
14+
15+
struct OneSignalWidgetLiveActivity: Widget {
16+
var body: some WidgetConfiguration {
17+
ActivityConfiguration(for: OneSignalWidgetAttributes.self) { context in
18+
VStack {
19+
Text("Hello \(context.attributes.name) \(context.state.emoji)")
20+
}
21+
.activityBackgroundTint(Color.cyan)
22+
.activitySystemActionForegroundColor(Color.black)
23+
24+
} dynamicIsland: { context in
25+
DynamicIsland {
26+
DynamicIslandExpandedRegion(.leading) {
27+
Text("Leading")
28+
}
29+
DynamicIslandExpandedRegion(.trailing) {
30+
Text("Trailing")
31+
}
32+
DynamicIslandExpandedRegion(.bottom) {
33+
Text("Bottom \(context.state.emoji)")
34+
}
35+
} compactLeading: {
36+
Text("L")
37+
} compactTrailing: {
38+
Text("T \(context.state.emoji)")
39+
} minimal: {
40+
Text(context.state.emoji)
41+
}
42+
.widgetURL(URL(string: "http://www.apple.com"))
43+
.keylineTint(Color.red)
44+
}
45+
}
46+
}

examples/demo/ios/Podfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ if linkage != nil
1414
use_frameworks! :linkage => linkage.to_sym
1515
end
1616

17+
target 'OneSignalNotificationServiceExtension' do
18+
# use_frameworks! :linkage => :static
19+
pod 'OneSignalXCFramework', '>= 5.0.0', '< 6.0'
20+
end
21+
22+
target 'OneSignalWidgetExtension' do
23+
# use_frameworks! :linkage => :static
24+
pod 'OneSignalXCFramework', '>= 5.0.0', '< 6.0'
25+
end
26+
1727
target 'demo' do
1828
config = use_native_modules!
1929

0 commit comments

Comments
 (0)