Commit Graph

37 Commits

Author SHA1 Message Date
Chace Liang 58202b7ba4 expose remote/local flag from native side instead of JS side
Reviewed By: hedgerwang

Differential Revision: D3536661

fbshipit-source-id: ae613daabe2ae581ebeabd8649b529d5fe6c5493
2016-07-12 22:58:20 -07:00
Kyle Corbitt 57d45235ec Correctly passes localNotification to app on wakeup
Summary:
Currently if an RN app is started in response to a remote notification, that notification's data is available on startup via `PushNotificationIOS.popInitialNotification()`. However, if the app is started in response to a "local" notification, that information is never passed in. This PR modifies the `popInitialNotification` behavior so it will return the notification used to launch the app, no matter if it was local or remote.

I've tested this change in my app and ensured that when the app is woken up with a `localNotification` it's passed in to `PushNotificationIOS.popInitialNotification`. I've also tested that the `localNotification` event continues working as before.
Closes https://github.com/facebook/react-native/pull/7765

Differential Revision: D3417267

Pulled By: nicklockwood

fbshipit-source-id: 0b5b432e9a75dda7d3c50289a3bf0f1c1ffcf061
2016-06-10 05:28:41 -07:00
Joshua Pinter 5b4b027477 Add get scheduled local notifications
Summary:
_(This is a remake of #6907, which I botched pretty good with a rebase.)_

This returns an `Array` of Local Notifications that have been scheduled to be delivered.

Available attributes on return Notification object (if set in the local notification itself):

`alertAction`
`alertBody`
`applicationIconBadgeNumber`
`category`
`fireDate`
`soundName`
`userInfo`

More could be added to this but I just matched what was available in the `Object` passed to `presentLocalNotification` and `scheduleLocalNotification`.

**Motivation**

I needed to determine the number and other details about local notifications that were already scheduled. There is an API for this in iOS but one hadn't been built yet for React Native.

I created the Obj-C method and updated the documentation in `PushNotificationIOS.js` as well.

**Usage:**

```js
PushNotificationIOS.getScheduledLocalNotifications( (notifications) => {
  console.log(notifications);
});
```

**Sample Output:**

```js
[
  Object {
    aler
Closes https://github.com/facebook/react-native/pull/7937

Differential Revision: D3392476

Pulled By: javache

fbshipit-source-id: d83f419bfcfbdaf9b955724dcf5cfe26834895fb
2016-06-06 09:28:24 -07:00
Jonathan Stanton f4dbf37ba8 PushNotificationIOS requestPermission promisified
Summary:
**Motivation**
Today it's hard to build a good flow around requesting permissions if we don't know when the user rejects the push notification permission.

With this PR I wrap `PushNotificationIOS#requestPermission` in a promise. The promise will return with the updated permissions when the user accepts, rejects or has previously rejected the permission.

An example flow of how an app should handle push notifications with the change proposed:
1) Show user an explanation of push notification permissions with a button to enable,
2) User presses the enable push notifications button,
3) If the user accepts -> take them into the app,
4) if the user rejects -> explain how to enable permission in the settings app.
5) My app will now store some state about how it has asked permissions for push notifications so that the next time the user is taken through this flow they will go straight to step 4.

Without this change we could listen to the `register` event that PushNotificationIOS fires on the success sc
Closes https://github.com/facebook/react-native/pull/7900

Differential Revision: D3387424

Pulled By: nicklockwood

fbshipit-source-id: e27df41e83216e4e2a14d1e42c6b26e72236f48c
2016-06-03 16:28:30 -07:00
Nick Lockwood 1623e34c51 Updated Linking and PushNotificationIOS modules to use NativeEventEmitter
Reviewed By: javache

Differential Revision: D3352819

fbshipit-source-id: d218791a16aba597d2544691ef993711cf00522c
2016-05-27 10:28:23 -07:00
Nick Lockwood b71db11554 Update RCTNetworking, RCTNetInfo and RCTLocationManager to use new events system
Summary: Updated networking and geolocation to use the new events system.

Reviewed By: bestander

Differential Revision: D3346129

fbshipit-source-id: 957716e54d7af8c4a6783f684098e92e92f19654
2016-05-25 04:28:36 -07:00
Konstantin Raev 2de0323182 Reverted commit D3339945
Summary: Updated networking and geolocation to use the new events system.

Reviewed By: javache

Differential Revision: D3339945

fbshipit-source-id: 01d307cf8a0aea3a404c87c6205132c42290abb1
2016-05-24 12:43:30 -07:00
Nick Lockwood 3f08fe4b7f Update RCTNetworking, RCTNetInfo and RCTLocationManager to use new events system
Summary: Updated networking and geolocation to use the new events system.

Reviewed By: javache

Differential Revision: D3339945

fbshipit-source-id: f1332fb2aab8560e4783739e223c1f31d583cfcf
2016-05-24 10:29:00 -07:00
Nick Lockwood e72163f0f2 Added explicit init to observer modules
Summary:
Modules which call JS methods directly, or use `sendDeviceEventWithName:`, can trigger effects in JS without ever being referenced from the JS code. This breaks some assumptions in my earlier diff about when modules can be lazily loaded.

Pending a better solution, I've put explicit `init` methods in these modules to ensure they are eagerly initialized (the downside to this is that they'll still be initialized even if they are never used).

Reviewed By: javache

Differential Revision: D3258232

fb-gh-sync-id: f925bc2e5339c1fbfcc244d4613062c5ab848fc2
fbshipit-source-id: f925bc2e5339c1fbfcc244d4613062c5ab848fc2
2016-05-04 07:07:24 -07:00
alvaromb 84e696867b Added badge icon number and alert action
Summary:
Added support for setting an optional badge icon number and alert action when using local notifications.
Closes https://github.com/facebook/react-native/pull/2931

Differential Revision: D3212448

Pulled By: mkonicek

fb-gh-sync-id: 063efcdd259b2a43f39812f57a71e8489ab33653
fbshipit-source-id: 063efcdd259b2a43f39812f57a71e8489ab33653
2016-04-29 05:37:27 -07:00
Jacob Turner 5c418655bf Remove duplicate register call
Summary:Hello!

As described in #3288, the `PushNotificationsIOS` `register` callback fires twice.  See that issue for discussion.

There wasn't any feedback on a proposed PR, so this is the first effort.  This change does make the register callback act as expected on my device.  I can make any changes necessary.

Thanks!
Closes https://github.com/facebook/react-native/pull/6111

Differential Revision: D2970806

Pulled By: nicklockwood

fb-gh-sync-id: a8d0b53210f85cc24b4befdb0e90af46512fa4fb
shipit-source-id: a8d0b53210f85cc24b4befdb0e90af46512fa4fb
2016-02-24 03:56:31 -08:00
Alonso Holmes 183d6a088c Adds category and alertAction properties to local notification details object
Summary:In order to use iOS notification actions with local notifications, we need to be able to specify a category string. This PR adds a category property to the `details` object used to create a local notification.

I also added support for the `alertAction` property, which is used to control the "slide to {alertAction}" text beneath the notification.

Finally, I added the doc for `userInfo` to `presentLocalNotification` (previously was only documented for `scheduleLocalNotification`.

**Test plan (required)**

I implemented the example from the [react-native-ios-notification-actions README](https://github.com/holmesal/react-native-ios-notification-actions), and created a couple of actions and grouped them under a category with identifier `something_happened`.

Prior to the changes in this PR, the shown local notification would not contain any actions.

With the changes in this PR, the shown local notification contains the specified actions.

Like so:
![demo](https://camo.githubusercontent.com/c4a86
Closes https://github.com/facebook/react-native/pull/5994

Differential Revision: D2953919

Pulled By: nicklockwood

fb-gh-sync-id: a05a9ea9ae8c150ff0714e106410e094c2747eca
shipit-source-id: a05a9ea9ae8c150ff0714e106410e094c2747eca
2016-02-19 05:19:34 -08:00
slycoder 758d9e8304 Add observers for local notifications
Summary:
This commit adds the delegate hooks so that local notifications get
passed onto the JS and adds a new event listener type for local
notifications.

Also add functions to clear local notifications
Closes https://github.com/facebook/react-native/pull/2084

Reviewed By: svcscm

Differential Revision: D2908096

Pulled By: nicklockwood

fb-gh-sync-id: 759d299ea35abea177e72934076297d666d3ea20
shipit-source-id: 759d299ea35abea177e72934076297d666d3ea20
2016-02-09 05:46:33 -08:00
pecheriere ac72611bb1 Add soundName config for UILocalNotification
Summary:
Current version wasn't triggering any sound when a local notification was fired. I added the possibility to provide a custom sound and fallback to the default iOS sound if not provided.
Closes https://github.com/facebook/react-native/pull/4836

Reviewed By: svcscm

Differential Revision: D2807381

Pulled By: bestander

fb-gh-sync-id: c25e8f3c30a0714a5d9558c0c1fe344d0e93321e
2016-01-07 12:01:26 -08:00
Michelle Todd 1dc5dca604 Rename methods in RCTPushNotificationManager so app store doesn't warn
Summary:
Including RCTPushNotificationManager is required for local notifications, which don't require a Push Notifications entitlement on your provisioning profile. However, if you don't have the entitlement, the app store warns you when you push an app build that contains `application:didRegisterForRemoteNotificationsWithDeviceToken:`, even if it isn't being called. This renames the methods so they have different names from the ones on UIApplication so the app store doesn't warn about them.
Closes https://github.com/facebook/react-native/pull/4897

Reviewed By: spicyj

Differential Revision: D2780533

Pulled By: nicklockwood

fb-gh-sync-id: 1a688f1ebd3cc9f86ba340ce453fdbfb46949839
2016-01-05 02:43:29 -08:00
Nick Lockwood 060664fd3d Refactored module access to allow for lazy loading
Summary: public

The `bridge.modules` dictionary provides access to all native modules, but this API requires that every module is initialized in advance so that any module can be accessed.

This diff introduces a better API that will allow modules to be initialized lazily as they are needed, and deprecates `bridge.modules` (modules that use it will still work, but should be rewritten to use `bridge.moduleClasses` or `-[bridge moduleForName/Class:` instead.

The rules are now as follows:

* Any module that overrides `init` or `setBridge:` will be initialized on the main thread when the bridge is created
* Any module that implements `constantsToExport:` will be initialized later when the config is exported (the module itself will be initialized on a background queue, but  `constantsToExport:` will still be called on the main thread.
* All other modules will be initialized lazily when a method is first called on them.

These rules may seem slightly arcane, but they have the advantage of not violating any assumptions that may have been made by existing code - any module written under the original assumption that it would be initialized synchronously on the main thread when the bridge is created should still function exactly the same, but modules that avoid overriding `init` or `setBridge:` will now be loaded lazily.

I've rewritten most of the standard modules to take advantage of this new lazy loading, with the following results:

Out of the 65 modules included in UIExplorer:

* 16 are initialized on the main thread when the bridge is created
* A further 8 are initialized when the config is exported to JS
* The remaining 41 will be initialized lazily on-demand

Reviewed By: jspahrsummers

Differential Revision: D2677695

fb-gh-sync-id: 507ae7e9fd6b563e89292c7371767c978e928f33
2015-11-25 04:49:45 -08:00
Nick Lockwood fa0b45c58b Replaced RCTSparseArray with NSDictionary
Reviewed By: jspahrsummers

Differential Revision: D2651920

fb-gh-sync-id: 953e2ea33abfc7a3a553da95b13e9ab2bccc5a1c
2015-11-14 10:28:28 -08:00
Adam Terlson da250671e5 Add support for cancelAllLocalNotifications
Summary: Closes https://github.com/facebook/react-native/pull/2980

Reviewed By: svcscm

Differential Revision: D2550080

Pulled By: javache

fb-gh-sync-id: 76a7088f4f86191b02e6c176e4a8a7bc85f90835
2015-10-16 10:57:25 -07:00
Danny van der Jagt 200b81172e Fix for IOS 8
Summary: **Problem**
Using push notifications in IOS 8 will throw this error:
`registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.`
The problem is that the check is running on compile instead of runtime.

**Solution**
If have changed the compile if statement to a runtime if statement. The fix is tested on: IOS 7.1 and 8.* and everything is working now.
This solution is also discussed in: https://github.com/facebook/react-native/issues/1613 and it was part of  https://github.com/facebook/react-native/pull/1979. (is being separated to keep things moving)

Please let me know what you think.Closes https://github.com/facebook/react-native/pull/2332

Reviewed By: @​svcscm

Differential Revision: D2490987

Pulled By: @ericvicenti
2015-09-30 21:02:31 -07:00
Yusef Napora 2f9bd1f62f App Extension support
Summary: This adds workarounds for the code that was preventing React from compiling when linked against an iOS App Extension target.

Some iOS APIs are unavailable to App Extensions, and Xcode's static analysis will catch attempts to use methods that have been flagged as unavailable.

React currently uses two APIs that are off limits to extensions: `[UIApplication sharedApplication]` and `[UIAlertView initWith ...]`.

This commit adds a helper function to `RCTUtils.[hm]` called `RCTRunningInAppExtension()`, which returns `YES` if, at runtime, it can be determined that we're running in an app extension (by checking whether the path to `[NSBundle mainBundle]` has the `"appex"` path extension).

It also adds a `RCTSharedApplication()` function, which will return `nil` if running in an App Extension. If running in an App, `RCTSharedApplication()` calls `sharedApplication` by calling `performSelector:` on the `UIApplication` class.  This passes the static analysis check, and, in my opinion, obeys the "spirit of th
Closes https://github.com/facebook/react-native/pull/1895

Reviewed By: @​svcscm

Differential Revision: D2224128

Pulled By: @nicklockwood
2015-09-22 10:46:26 -07:00
Nick Lockwood 88e0bbc469 Ran Convert > To Modern Objective C Syntax 2015-08-25 01:08:49 -08:00
Nick Lockwood 8d1e02b8bd Convert alloc/init to new to please linter 2015-08-17 08:46:00 -07:00
Jacob Rosenthal a8cb47e011 add local notification api schedule and present
Summary:
Add local notifications to the push library.
```
  var PushNotificationIOS = React.PushNotificationIOS;
  PushNotificationIOS.requestPermissions();

  var notification = {
    "fireDate": Date.now() + 10000,
    "alertBody":"Whats up pumpkin"
  };

  PushNotificationIOS.scheduleLocalNotification(notification);
 //lock screen or move away from app
```

Apple has another api for pushing immediately instead of scheduling, like when your background delegate has been called with some new data (bluetooth, location, etc)
```
  var PushNotificationIOS = React.PushNotificationIOS;
  PushNotificationIOS.requestPermissions();

  var notification = {
    "alertBody":"Whats up pumpkin"
  };

  PushNotificationIOS.presentLocalNotification(notification);
 //lock screen or move away from app
```

Closed https://github.com/facebook/react-native/pull/843 looks related:

See https://developer.apple.com/library/ios/documentation/iPhone/Reference/UILocalNotification_Class/ for much more available in
Closes https://github.com/facebook/react-native/pull/1616
Github Author: Jacob Rosenthal <jakerosenthal@gmail.com>
2015-07-14 09:08:30 -08:00
Shuangzuan df8287d8ee [PushNotification] Unregister for remote notifications support.
Summary:
See iOS Developer Library: [- unregisterForRemoteNotifications](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/index.html#//apple_ref/occ/instm/UIApplication/unregisterForRemoteNotifications).

Unregister for all remote notifications received via Apple Push Notification service.

**Discussion**
You should call this method in rare circumstances only, such as when a new version of the app removes support for all types of remote notifications. Users can temporarily prevent apps from receiving remote notifications through the Notifications section of the Settings app. Apps unregistered through this method can always re-register.
Closes https://github.com/facebook/react-native/pull/1520
Github Author: Shuangzuan <shuangzuan.he@icloud.com>

Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-15 12:13:46 -08:00
Nick Lockwood 650fc9de4c Increased warning levels to -Wall -Wextra, and fixed Xcode 7 beta issues
Summary:
@public

I've increased the warning levels in the OSS frameworks, which caught a bunch of minor issues. I also fixed some new errors in Xcode 7 relating to designated initializers and TLS security.

Test Plan:
* Test the sample apps and make sure they still work.
* Run tests.
2015-06-15 07:52:50 -08:00
Tadeu Zagallo 2a7adfb815 [ReactNative] Use RCTNullIfNill and (id)kCFNull
Summary:
@public

Use consistent `null` handling:

`value || null`                ->  `RCTNullIfNil(value)`
`value == null ? nil : value`  ->  `RCTNilIfNull(value)`
`[NSNull null]`                ->  `(id)kCFNull`

Test Plan: The tests should be enough.
2015-06-12 11:03:10 -08:00
Tadeu Zagallo 847dff8d75 [ReactNative] Make JavaScript executors bridge modules
Summary:
@public

This is the first of a few diffs that change the way the executors are handled
by the bridge.

For they are just promoted to modules, so they are automatically loaded by the bridge.

Test Plan:
Tested on UIExplorer, Catalyst and MAdMan.
Tested all the 3 executors, everything looks fine.
2015-06-09 15:40:55 -08:00
Andrew Imm 89a1e94a15 Add an event for remote notification registration, and improve permissions request
Summary:
In order to add Push support to the Parse JS SDK in React Native, we need a way to receive the APNS device token from the JS context. This adds another event to PushNotificationIOS, so that code can respond to a successful registration.

Additionally, I've updated the `requestPermissions` call to accept an optional map of parameters. This way, developers can request a subset of user notification types.
Closes https://github.com/facebook/react-native/pull/1304
Github Author: Andrew Imm <andrewi@fb.com>

Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-03 14:06:44 -08:00
Kevin Gozali 824da1bada [ReactNative] pass in launchOptions to relevant bridged modules 2015-04-30 14:51:09 -08:00
Tadeu Zagallo d293bed5ab [ReactNative] Fix analyze errors on oss 2015-04-24 08:28:35 -08:00
Tadeu Zagallo 4616037428 [ReactNative] Fix push notifications on iOS7 2015-04-10 03:09:35 -08:00
Alex Akers 8a57c4e980 [React Native] RCT_EXPORT lvl.2 2015-04-08 08:34:10 -08:00
Nick Lockwood bf4868edda Added non-class-scanning-based approach fror registering js methods 2015-04-08 05:45:20 -08:00
Tadeu Zagallo 8679c0bc96 [ReactNative] Add deep linking api 2015-03-25 19:01:08 -08:00
Nick Lockwood 94db4facf5 Unfork UIManager 2015-03-24 17:24:51 -08:00
Tadeu Zagallo fe0527a7c4 [ReactNative] Remove auto permission request from setAppIconBadgeNumber 2015-03-24 10:33:46 -08:00
Tadeu Zagallo 8ae0eacf17 [ReactNative] Open Source PushNotifications and move Badge Number methods and permission into it 2015-03-24 04:31:34 -08:00