Last active
August 29, 2015 14:21
-
-
Save betahikaru/a981fba4ed9fcfd02328 to your computer and use it in GitHub Desktop.
[React Native] 設定.appを開くNativeModuleを作った ref: http://qiita.com/betahikaru/items/2b788e84f8d67ac682c0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; | |
BOOL result = [[UIApplication sharedApplication] openURL:url]; | |
if (result) { /* 成功 */ } else { /* 失敗 */ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 以上 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var React = require('react-native'); | |
var { | |
..., | |
NativeModules, | |
} = React; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var { | |
OpenSettingAppModule, | |
} = NativeModules; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OpenSettingAppModule.openSettingsApp((result) => { | |
/* 設定.appを開いた後の行いたい処理 */ | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var callback = function(result) { | |
/* 設定.appを開いた後の行いたい処理 */ | |
} | |
OpenSettingAppModule.openSettingsApp(callback); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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