瀏覽代碼

return promise from `openSettings` resolve when user returns to app

Yonah Forst 8 年之前
父節點
當前提交
f54d001cbc

+ 7
- 2
Example/Example.js 查看文件

@@ -41,6 +41,11 @@ export default class Example extends Component {
41 41
     }
42 42
   }
43 43
 
44
+  _openSettings() {
45
+    return Permissions.openSettings()
46
+      .then(() => alert('back to app!!'))
47
+  }
48
+
44 49
   _updatePermissions(types) {
45 50
     Permissions.checkMultiplePermissions(types)
46 51
       .then(status => {
@@ -71,7 +76,7 @@ export default class Example extends Component {
71 76
             "There was a problem getting your permission. Please enable it from settings.",
72 77
             [
73 78
               {text: 'Cancel', style: 'cancel'},
74
-              {text: 'Open Settings', onPress: Permissions.openSettings },
79
+              {text: 'Open Settings', onPress: this._openSettings.bind(this) },
75 80
             ]
76 81
           )
77 82
         }
@@ -111,7 +116,7 @@ export default class Example extends Component {
111 116
           </TouchableHighlight>
112 117
 
113 118
           <TouchableHighlight 
114
-            onPress={Permissions.openSettings}>
119
+            onPress={this._openSettings.bind(this)}>
115 120
             <Text style={styles.text}>Open settings</Text>
116 121
           </TouchableHighlight>
117 122
         </View>

+ 13
- 1
ReactNativePermissions.m 查看文件

@@ -59,14 +59,26 @@ RCT_REMAP_METHOD(canOpenSettings, canOpenSettings:(RCTPromiseResolveBlock)resolv
59 59
     resolve(@(UIApplicationOpenSettingsURLString != nil));
60 60
 }
61 61
 
62
-RCT_EXPORT_METHOD(openSettings)
62
+    
63
+RCT_EXPORT_METHOD(openSettings:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
63 64
 {
64 65
     if (@(UIApplicationOpenSettingsURLString != nil)) {
66
+        
67
+        NSNotificationCenter * __weak center = [NSNotificationCenter defaultCenter];
68
+        id __block token = [center addObserverForName:UIApplicationDidBecomeActiveNotification
69
+                                               object:nil
70
+                                                queue:nil
71
+                                           usingBlock:^(NSNotification *note) {
72
+                                               [center removeObserver:token];
73
+                                               resolve(@YES);
74
+                                           }];
75
+        
65 76
         NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
66 77
         [[UIApplication sharedApplication] openURL:url];
67 78
     }
68 79
 }
69 80
 
81
+
70 82
 RCT_REMAP_METHOD(getPermissionStatus, getPermissionStatus:(RNPType)type json:(id)json resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
71 83
 {
72 84
     NSString *status;

ReactNativePermissions.xcodeproj/xcuserdata/Yonah.xcuserdatad/xcschemes/ReactNativeHeading.xcscheme → ReactNativePermissions.xcodeproj/xcuserdata/Yonah.xcuserdatad/xcschemes/ReactNativePermissions.xcscheme 查看文件


+ 1
- 1
package.json 查看文件

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "react-native-permissions",
3
-  "version": "0.2.7",
3
+  "version": "0.3.0",
4 4
   "repository": {
5 5
     "type": "git",
6 6
     "url": "https://github.com/joshblour/react-native-permissions.git"