{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/react-native/issues/8714","repository_url":"https://api.github.com/repos/facebook/react-native","labels_url":"https://api.github.com/repos/facebook/react-native/issues/8714/labels{/name}","comments_url":"https://api.github.com/repos/facebook/react-native/issues/8714/comments","events_url":"https://api.github.com/repos/facebook/react-native/issues/8714/events","html_url":"https://github.com/facebook/react-native/issues/8714","id":165068196,"number":8714,"title":"What is the method can be used to send an event from native module to JS？","user":{"login":"livoras","id":6436132,"avatar_url":"https://avatars.githubusercontent.com/u/6436132?v=3","gravatar_id":"","url":"https://api.github.com/users/livoras","html_url":"https://github.com/livoras","followers_url":"https://api.github.com/users/livoras/followers","following_url":"https://api.github.com/users/livoras/following{/other_user}","gists_url":"https://api.github.com/users/livoras/gists{/gist_id}","starred_url":"https://api.github.com/users/livoras/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/livoras/subscriptions","organizations_url":"https://api.github.com/users/livoras/orgs","repos_url":"https://api.github.com/users/livoras/repos","events_url":"https://api.github.com/users/livoras/events{/privacy}","received_events_url":"https://api.github.com/users/livoras/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-07-12T12:29:56Z","updated_at":"2016-07-22T02:15:53Z","closed_at":"2016-07-13T01:44:10Z","body":"According to React Native [documentation](https://facebook.github.io/react-native/docs/native-modules-ios.html#sending-events-to-javascript), you can use `sendAppEventWithName` to send an event from native code to JS. But in my XCode, code suggestions tell me that this method is deprecated.\r\n\r\n![image](https://cloud.githubusercontent.com/assets/6436132/16766881/2eed0fc6-486f-11e6-82a5-cf76b89946ad.png)\r\n\r\nThis [issue](https://github.com/facebook/react-native/issues/394) indicates that `sendDeviceEventWithName` should work but actually it's also deprecated.\r\n\r\nWhat is the proper way to send an event to JS?"},"comment":{"url":"https://api.github.com/repos/facebook/react-native/issues/comments/234437319","html_url":"https://github.com/facebook/react-native/issues/8714#issuecomment-234437319","issue_url":"https://api.github.com/repos/facebook/react-native/issues/8714","id":234437319,"user":{"login":"aaronksaunders","id":524953,"avatar_url":"https://avatars.githubusercontent.com/u/524953?v=3","gravatar_id":"","url":"https://api.github.com/users/aaronksaunders","html_url":"https://github.com/aaronksaunders","followers_url":"https://api.github.com/users/aaronksaunders/followers","following_url":"https://api.github.com/users/aaronksaunders/following{/other_user}","gists_url":"https://api.github.com/users/aaronksaunders/gists{/gist_id}","starred_url":"https://api.github.com/users/aaronksaunders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aaronksaunders/subscriptions","organizations_url":"https://api.github.com/users/aaronksaunders/orgs","repos_url":"https://api.github.com/users/aaronksaunders/repos","events_url":"https://api.github.com/users/aaronksaunders/events{/privacy}","received_events_url":"https://api.github.com/users/aaronksaunders/received_events","type":"User","site_admin":false},"created_at":"2016-07-22T02:15:53Z","updated_at":"2016-07-22T02:15:53Z","body":"I got it to work in swift... here is the snippets\r\n\r\n```Swift\r\n// in my module...\r\n@objc(YourModule)\r\nclass YourModule: RCTEventEmitter {\r\n    \r\n  \r\n  override func supportedEvents() -> [String]! {\r\n    return [\"UploadProgress\"]\r\n  }\r\n```\r\n\r\nfurther down in the class\r\n\r\n```Swift\r\n    // A progress event occurred, notify the user...\r\n    uploadTask.observeStatus(.Progress) { (snapshot:FIRStorageTaskSnapshot) in\r\n      \r\n      if let progress = snapshot.progress {\r\n        \r\n        let percentComplete =  Double(progress.completedUnitCount) / Double(fs)\r\n        \r\n        let ret : [String:AnyObject] = [\r\n          \"completedUnitCount\": String(progress.completedUnitCount),\r\n          \"percentComplete\": String(percentComplete),\r\n          \"totalUnitCount\": String(fs)\r\n        ]\r\n        \r\n        self.sendEventWithName(\"UploadProgress\", body: ret )\r\n      }\r\n    }\r\n```\r\n\r\nIn my react-native code\r\n\r\n```javascript\r\n    const myModuleEvt = new NativeEventEmitter(NativeModules.YourModule)\r\n    var subscription = myModuleEvt.addListener(\r\n      'UploadProgress',\r\n      (progress) => {\r\n        console.log(\"UploadProgress\")\r\n        console.log(JSON.stringify(progress, null, 2))\r\n      }\r\n    );\r\n```"}}
{"actor":{"display_login":"aaronksaunders"}}