Bladeren bron

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

Yonah Forst 8 jaren geleden
bovenliggende
commit
f54d001cbc

+ 7
- 2
Example/Example.js Bestand weergeven

41
     }
41
     }
42
   }
42
   }
43
 
43
 
44
+  _openSettings() {
45
+    return Permissions.openSettings()
46
+      .then(() => alert('back to app!!'))
47
+  }
48
+
44
   _updatePermissions(types) {
49
   _updatePermissions(types) {
45
     Permissions.checkMultiplePermissions(types)
50
     Permissions.checkMultiplePermissions(types)
46
       .then(status => {
51
       .then(status => {
71
             "There was a problem getting your permission. Please enable it from settings.",
76
             "There was a problem getting your permission. Please enable it from settings.",
72
             [
77
             [
73
               {text: 'Cancel', style: 'cancel'},
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
           </TouchableHighlight>
116
           </TouchableHighlight>
112
 
117
 
113
           <TouchableHighlight 
118
           <TouchableHighlight 
114
-            onPress={Permissions.openSettings}>
119
+            onPress={this._openSettings.bind(this)}>
115
             <Text style={styles.text}>Open settings</Text>
120
             <Text style={styles.text}>Open settings</Text>
116
           </TouchableHighlight>
121
           </TouchableHighlight>
117
         </View>
122
         </View>

+ 13
- 1
ReactNativePermissions.m Bestand weergeven

59
     resolve(@(UIApplicationOpenSettingsURLString != nil));
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
     if (@(UIApplicationOpenSettingsURLString != nil)) {
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
         NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
76
         NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
66
         [[UIApplication sharedApplication] openURL:url];
77
         [[UIApplication sharedApplication] openURL:url];
67
     }
78
     }
68
 }
79
 }
69
 
80
 
81
+
70
 RCT_REMAP_METHOD(getPermissionStatus, getPermissionStatus:(RNPType)type json:(id)json resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
82
 RCT_REMAP_METHOD(getPermissionStatus, getPermissionStatus:(RNPType)type json:(id)json resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
71
 {
83
 {
72
     NSString *status;
84
     NSString *status;

ReactNativePermissions.xcodeproj/xcuserdata/Yonah.xcuserdatad/xcschemes/ReactNativeHeading.xcscheme → ReactNativePermissions.xcodeproj/xcuserdata/Yonah.xcuserdatad/xcschemes/ReactNativePermissions.xcscheme Bestand weergeven


+ 1
- 1
package.json Bestand weergeven

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