Skip to content

Commit af12b80

Browse files
committed
Updated README.md
• Added instructions for how to implement the react-native SDK using a Swift app delegate instead of Objective-C
1 parent c66074e commit af12b80

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

README.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ android {
159159

160160
### Adding the Code
161161

162+
<details><summary>Objective-C</summary><p>
163+
162164
* in `AppDelegate.h`:
163165
* Import `RCTOneSignal.h`:
164166

@@ -186,13 +188,49 @@ android {
186188
self.oneSignal = [[RCTOneSignal alloc] initWithLaunchOptions:launchOptions
187189
appId:@"YOUR_ONESIGNAL_APP_ID"];
188190
```
189-
191+
* You can also pass settings to OneSignal to control various effects, such as whether OneSignal automatically asks for permission to send push notifications shortly after launch or not.
190192
```objc
191-
// For requiring push notification permissions manually.
192193
self.oneSignal = [[RCTOneSignal alloc] initWithLaunchOptions:launchOptions
193194
appId:@"YOUR_ONESIGNAL_APP_ID"
194195
settings:@{kOSSettingsKeyAutoPrompt: @false}];
195196
```
197+
</p></details>
198+
199+
<details><summary>Swift</summary><p>
200+
201+
* If you don't already have one, create an Objective-C Bridging header for your project (`YourProjectName-Bridging-Header.h`) and import the React-Native-Onesignal library:
202+
203+
```objc
204+
#import <RCTOneSignal.h>
205+
```
206+
* In your AppDelegate, add the following property:
207+
208+
```swift
209+
var oneSignal : RCTOneSignal!
210+
```
211+
212+
* On the `application didFinishLaunchingWithOptions` method, insert the following code (replace YOUR_ONESIGNAL_APP_ID with your OneSignal app ID):
213+
214+
```swift
215+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
216+
217+
self.oneSignal = RCTOneSignal(launchOptions: launchOptions, appId: "YOUR_ONESIGNAL_APP_ID");
218+
}
219+
220+
```
221+
222+
* You can also pass settings to OneSignal to control various effects, such as whether OneSignal automatically asks for permission to send push notifications shortly after launch or not.
223+
224+
```swift
225+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
226+
227+
self.oneSignal = RCTOneSignal(launchOptions: launchOptions, appId: "YOUR_ONESIGNAL_APP_ID", settings: [kOSSettingsKeyAutoPrompt : false])
228+
}
229+
```
230+
231+
</p></details>
232+
233+
196234

197235
### Add Notification Service Extension
198236
This step is optional but highly recommended. The `OneSignalNotificationServiceExtension` allows your application (in iOS) to receive rich notifications with images and/or buttons. If you do not follow this step, your application will not be able to show images in push notifications, and won't be able to add action buttons to notifications either.

0 commit comments

Comments
 (0)