Skip to content

Instantly share code, notes, and snippets.

@betahikaru
Last active August 29, 2015 14:21
Show Gist options
  • Save betahikaru/a981fba4ed9fcfd02328 to your computer and use it in GitHub Desktop.
Save betahikaru/a981fba4ed9fcfd02328 to your computer and use it in GitHub Desktop.
[React Native] 設定.appを開くNativeModuleを作った ref: http://qiita.com/betahikaru/items/2b788e84f8d67ac682c0
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(canOpenSettingsApp:(RCTResponseSenderBlock)callback)
{
if (/* iOS8以上? */) {
/* コールバックに渡す引数は、1つでも配列として渡す必要あり */
callback(@[true]);
} else {
callback(@[false]);
}
RCTLogInfo(@"Finish");
}
RCT_EXPORT_METHOD(openSettingsApp:(RCTResponseSenderBlock)callback)
{
/* 設定.appを開く処理 */
if (/* 成功 */) {
callback(@[@true]);
} else {
callback(@[@false]);
}
RCTLogInfo(@"Finish");
}
@end
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
BOOL result = [[UIApplication sharedApplication] openURL:url];
if (result) { /* 成功 */ } else { /* 失敗 */ }
UIDevice *device = [UIDevice currentDevice];
NSString *versionStr = [device systemVersion];
NSString *versionSupportedOpening = @"8.0";
NSComparisonResult resultCompare = [[device systemVersion]
compare:versionSupportedOpening
options:NSNumericSearch];
if (resultCompare != NSOrderedDescending) {
// iOS 8.0 未満
} else {
// iOS 8.0 以上
}
var React = require('react-native');
var {
...,
NativeModules,
} = React;
var {
OpenSettingAppModule,
} = NativeModules;
OpenSettingAppModule.openSettingsApp((result) => {
/* 設定.appを開いた後の行いたい処理 */
});
var callback = function(result) {
/* 設定.appを開いた後の行いたい処理 */
}
OpenSettingAppModule.openSettingsApp(callback);
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "RCTBridgeModule.h"
#import "RCTLog.h"
@interface OpenSettingAppModule : NSObject<RCTBridgeModule>
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment