クイックスタート
このクイックスタートガイドで5-10分以内にNetFUNNEL 4 iOSエージェントを開始して実行してください。
このガイドでできること
- コードベース統合: iOSコードからNetFUNNEL関数を呼び出してトラフィック制御を適用
- 基本コントロール: ViewController進入、ボタンタップ、API呼び出しに対する進入速度制限
- 区間コントロール: 特定のアプリケーション区間内の同時ユーザー制御
制御タイプの選択
どの制御タイプを使用すべきかわかりませんか? 統合方法概要を確認して、基本コントロールと区間コントロールアプローチを比較し、ユースケースに最も適した方法を見つけてください。
事前要件
- NetFUNNELコンソールアクセス
- Xcode環境
- iOS開発の基本理解 (Swift/Objective-C)
- iOS 12.0以上
練習プロジェクト提供
練習用の基本プロジェクトが必要ですか? NetFUNNEL SDK統合の練習のための**iOSアプリケーション (Single ViewController)**テンプレートを含むサンプルプロジェクトを確認してください。
ステップ1: SDKインストールおよびエージェントの初期化
1.1 NetFUNNELコンソールからSDKダウンロード
- NetFUNNELコンソールにログイン
- 移動: Agent → Mobile Agent → iOS
- ZIPファイルダウンロード:
netfunnel-ios-agent-4.3.2-onprem.zip - ZIPファイルを抽出してフォルダ構造を確認:
netfunnel-ios-agent-4.3.2-onprem/
├── netfunnel-ios-agent-debug/
│ └── netfunnel_ios.xcframework
└── netfunnel-ios-agent-release/
└── netfunnel_ios.xcframework
1.2 プロジェクトにフレームワークを追加
1. Frameworksフォルダの作成:
- プロジェクトルートに
Frameworksフォルダを作成 netfunnel-ios-agent-debug/netfunnel_ios.xcframeworkをFrameworksフォルダにコピー (開発用)
2. Xcodeでフレームワークを登録:
- Project ▸ General ▸ Frameworks, Libraries, and Embedded Contentに移動
- **+をクリックしてAdd Files…**を選択
netfunnel_ios.xcframeworkファイルを選択- フレームワークがリストに表示されることを確認
3. Info.plistにインターネット権限を追加:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
1.3 エージェントの初期化
NetFUNNELコンソールから初期化コードを取得:
- Agent → Mobile Agent → iOSに移動
- 実際のクライアントIDが含まれた初期化コードをコピー
AppDelegateに追加:
重要: 最初に初期化する必要がある
application(_:didFinishLaunchingWithOptions:)でsuperを呼び出す前に初期化してください。このステップを省略すると = バイパスモード (保護なし)。
- Swift
- Objective-C
import UIKit
import Netfunnel_iOS
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Netfunnel.initialize(
clientId: "{{CLIENT_ID}}",
delegate: self
)
return true
}
}
#import <UIKit/UIKit.h>
#import <Netfunnel_iOS/Netfunnel.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[agent initializeWithClientId:@"{{CLIENT_ID}}"
delegate:self];
return YES;
}
@end
実際のコードを使用
プレースホルダー{{CLIENT_ID}}をNetFUNNELコンソールの実際のクライアントIDに置き換えてください。
ステップ2: 制御タイプの選択
オプションA: 基本コントロール (5分)
最適なユースケース: ViewController進入、ボタンタップ、API呼び出し
- プロジェクトにSDKを追加 (インストールおよび初期化を参照)
- NetFUNNELコンソールでセグメントを作成:
プロジェクト→セグメント→セグメント作成に移動- 基本コントロールを選択
- 進入許容数を
0に設定 (テスト用)
- ViewControllerにこのコードを追加:
- Swift
- Objective-C
import UIKit
import Netfunnel_iOS
class ViewController: UIViewController, NetfunnelDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// ユーザーがビューに進入するときにNetFUNNELを開始
Netfunnel.shared.nfStart(projectKey: "{{PROJECT_KEY}}", segmentKey: "{{SEGMENT_KEY}}")
}
// MARK: - NetfunnelDelegate Methods
func nfSuccess(projectKey: String, segmentKey: String, statusCode: Int, message: String) {
// ユーザーが進行できる - 元のロジックを実行
DispatchQueue.main.async {
self.setupUI()
}
}
func nfError(projectKey: String, segmentKey: String, statusCode: Int, message: String) {
// システムエラー - サービスの可用性のために元のロジックを進行
DispatchQueue.main.async {
self.setupUI()
}
}
func nfNetworkError(projectKey: String, segmentKey: String, statusCode: Int, message: String) {
// ネットワークエラー - ロギングのみ実行、ネットワーク回復モードに依存
print("NetFUNNEL Network error: \(message)")
}
func nfBlock(projectKey: String, segmentKey: String, statusCode: Int, message: String) {
// ユーザーがブロックされた - 適切なメッセージを表示
DispatchQueue.main.async {
let alert = UIAlertController(title: "Access Blocked", message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default))
self.present(alert, animated: true)
}
}
func nfClose(projectKey: String, segmentKey: String, statusCode: Int, message: String) {
// ユーザーが待合室を閉じた - 適切に処理
print("NetFUNNEL User closed waiting room: \(message)")
}
func nfContinue(projectKey: String, segmentKey: String, statusCode: Int, message: String, aheadWait: Int, behindWait: Int, waitTime: String, progressRate: Int) {
print("NetFUNNEL Continue: \(message), waitTime: \(waitTime)")
}
func nfComplete(projectKey: String, segmentKey: String, statusCode: Int, message: String) {
print("NetFUNNEL Key returned successfully")
}
// ユーザーが離れるときにキー返却
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
Netfunnel.shared.nfStop(projectKey: "{{PROJECT_KEY}}", segmentKey: "{{SEGMENT_KEY}}")
}
private func setupUI() {
// 元のUI設定ロジック
}
}
#import <UIKit/UIKit.h>
#import <Netfunnel_iOS/Netfunnel.h>
#import <Netfunnel_iOS/NetfunnelDelegate.h>
@interface ViewController : UIViewController <NetfunnelDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// ユーザーがビューに進入するときにNetFUNNELを開始
[[Netfunnel shared] nfStartWithProjectKey:@"{{PROJECT_KEY}}" segmentKey:@"{{SEGMENT_KEY}}"];
}
// MARK: - NetfunnelDelegate Methods
- (void)nfSuccessWithProjectKey:(NSString *)projectKey
segmentKey:(NSString *)segmentKey
statusCode:(NSInteger)statusCode
message:(NSString *)message {
// ユーザーが進行できる - 元のロジックを実行
dispatch_async(dispatch_get_main_queue(), ^{
[self setupUI];
});
}
- (void)nfErrorWithProjectKey:(NSString *)projectKey
segmentKey:(NSString *)segmentKey
statusCode:(NSInteger)statusCode
message:(NSString *)message {
// システムエラー - サービスの可用性のために元のロジックを進行
dispatch_async(dispatch_get_main_queue(), ^{
[self setupUI];
});
}
- (void)nfNetworkErrorWithProjectKey:(NSString *)projectKey
segmentKey:(NSString *)segmentKey
statusCode:(NSInteger)statusCode
message:(NSString *)message {
// ネットワークエラー - ロギングのみ実行、ネットワーク回復モードに依存
NSLog(@"NetFUNNEL Network error: %@", message);
}
- (void)nfBlockWithProjectKey:(NSString *)projectKey
segmentKey:(NSString *)segmentKey
statusCode:(NSInteger)statusCode
message:(NSString *)message {
// ユーザーがブロックされた - 適切なメッセージを表示
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Access Blocked"
message:message
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
});
}
- (void)nfCloseWithProjectKey:(NSString *)projectKey
segmentKey:(NSString *)segmentKey
statusCode:(NSInteger)statusCode
message:(NSString *)message {
// ユーザーが待合室を閉じた - 適切に処理
NSLog(@"NetFUNNEL User closed waiting room: %@", message);
}
- (void)nfContinueWithProjectKey:(NSString *)projectKey
segmentKey:(NSString *)segmentKey
statusCode:(NSInteger)statusCode
message:(NSString *)message
aheadWait:(NSInteger)aheadWait
behindWait:(NSInteger)behindWait
waitTime:(NSString *)waitTime
progressRate:(NSInteger)progressRate {
NSLog(@"NetFUNNEL Continue: %@, waitTime: %@", message, waitTime);
}
- (void)nfCompleteWithProjectKey:(NSString *)projectKey
segmentKey:(NSString *)segmentKey
statusCode:(NSInteger)statusCode
message:(NSString *)message {
NSLog(@"NetFUNNEL Key returned successfully");
}
// ユーザーが離れるときにキー返却
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[Netfunnel shared] nfStopWithProjectKey:@"{{PROJECT_KEY}}" segmentKey:@"{{SEGMENT_KEY}}"];
}
- (void)setupUI {
// 元のUI設定ロジック
}
@end
結果: ユーザーがViewControllerに進入するときに待合室が表示されます。
オプションB: 区間コントロール (10分)
最適なユースケース: マルチステッププロセス、同時ユーザー制限の維持
- プロジェクトにSDKを追加 (オプションAと同じ)
- NetFUNNELコンソールでセグメントを作成 (区間コントロールを選択)
- チェックアウト/決済フローにこのコードを追加:
- Swift
- Objective-C
import UIKit
import Netfunnel_iOS
class CheckoutViewController: UIViewController, NetfunnelDelegate {
// 区間開始 (例: チェックアウトプロセス)
func startCheckout() {
Netfunnel.shared.nfStartSection(projectKey: "{{PROJECT_KEY}}", segmentKey: "{{SEGMENT_KEY}}")
}
// MARK: - NetfunnelDelegate Methods
func nfSuccess(projectKey: String, segmentKey: String, statusCode: Int, message: String) {
// ユーザーが区間に進入した
DispatchQueue.main.async {
self.showCheckoutForm()
}
}
func nfError(projectKey: String, segmentKey: String, statusCode: Int, message: String) {
// システムエラー - サービスの可用性のために元のロジックを進行
DispatchQueue.main.async {
self.showCheckoutForm()
}
}
func nfNetworkError(projectKey: String, segmentKey: String, statusCode: Int, message: String) {
// ネットワークエラー - ロギングのみ実行、ネットワーク回復モードに依存
print("NetFUNNEL Network error: \(message)")
}
func nfBlock(projectKey: String, segmentKey: String, statusCode: Int, message: String) {
// ユーザーがブロックされた - 適切なメッセージを表示
DispatchQueue.main.async {
let alert = UIAlertController(title: "Access Blocked", message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default))
self.present(alert, animated: true)
}
}
func nfClose(projectKey: String, segmentKey: String, statusCode: Int, message: String) {
// ユーザーが待合室を閉じた - 適切に処理
print("NetFUNNEL User closed waiting room: \(message)")
}
func nfContinue(projectKey: String, segmentKey: String, statusCode: Int, message: String, aheadWait: Int, behindWait: Int, waitTime: String, progressRate: Int) {
print("NetFUNNEL Continue: \(message), waitTime: \(waitTime)")
}
func nfComplete(projectKey: String, segmentKey: String, statusCode: Int, message: String) {
print("NetFUNNEL Section key returned successfully")
}
// 区間終了 (例: 決済完了後)
func completeCheckout() {
// チェックアウト完了ロジック
processPayment()
// 成功した完了後にキー返却
Netfunnel.shared.nfStopSection(projectKey: "{{PROJECT_KEY}}", segmentKey: "{{SEGMENT_KEY}}")
}
private func showCheckoutForm() {
// チェックアウトフォーム設定ロジック
}
private func processPayment() {
// 決済処理ロジック
}
}
#import <UIKit/UIKit.h>
#import <Netfunnel_iOS/Netfunnel.h>
#import <Netfunnel_iOS/NetfunnelDelegate.h>
@interface CheckoutViewController : UIViewController <NetfunnelDelegate>
@end
@implementation CheckoutViewController
// 区間開始 (例: チェックアウトプロセス)
- (void)startCheckout {
[[Netfunnel shared] nfStartSectionWithProjectKey:@"{{PROJECT_KEY}}" segmentKey:@"{{SEGMENT_KEY}}"];
}
// MARK: - NetfunnelDelegate Methods
- (void)nfSuccessWithProjectKey:(NSString *)projectKey
segmentKey:(NSString *)segmentKey
statusCode:(NSInteger)statusCode
message:(NSString *)message {
// ユーザーが区間に進入した
dispatch_async(dispatch_get_main_queue(), ^{
[self showCheckoutForm];
});
}
- (void)nfErrorWithProjectKey:(NSString *)projectKey
segmentKey:(NSString *)segmentKey
statusCode:(NSInteger)statusCode
message:(NSString *)message {
// システムエラー - サービスの可用性のために元のロジックを進行
dispatch_async(dispatch_get_main_queue(), ^{
[self showCheckoutForm];
});
}
- (void)nfNetworkErrorWithProjectKey:(NSString *)projectKey
segmentKey:(NSString *)segmentKey
statusCode:(NSInteger)statusCode
message:(NSString *)message {
// ネットワークエラー - ロギングのみ実行、ネットワーク回復モードに依存
NSLog(@"NetFUNNEL Network error: %@", message);
}
- (void)nfBlockWithProjectKey:(NSString *)projectKey
segmentKey:(NSString *)segmentKey
statusCode:(NSInteger)statusCode
message:(NSString *)message {
// ユーザーがブロックされた - 適切なメッセージを表示
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Access Blocked"
message:message
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
});
}
- (void)nfCloseWithProjectKey:(NSString *)projectKey
segmentKey:(NSString *)segmentKey
statusCode:(NSInteger)statusCode
message:(NSString *)message {
// ユーザーが待合室を閉じた - 適切に処理
NSLog(@"NetFUNNEL User closed waiting room: %@", message);
}
- (void)nfContinueWithProjectKey:(NSString *)projectKey
segmentKey:(NSString *)segmentKey
statusCode:(NSInteger)statusCode
message:(NSString *)message
aheadWait:(NSInteger)aheadWait
behindWait:(NSInteger)behindWait
waitTime:(NSString *)waitTime
progressRate:(NSInteger)progressRate {
NSLog(@"NetFUNNEL Continue: %@, waitTime: %@", message, waitTime);
}
- (void)nfCompleteWithProjectKey:(NSString *)projectKey
segmentKey:(NSString *)segmentKey
statusCode:(NSInteger)statusCode
message:(NSString *)message {
NSLog(@"NetFUNNEL Section key returned successfully");
}
// 区間終了 (例: 決済完了後)
- (void)completeCheckout {
// チェックアウト完了ロジック
[self processPayment];
// 成功した完了後にキー返却
[[Netfunnel shared] nfStopSectionWithProjectKey:@"{{PROJECT_KEY}}" segmentKey:@"{{SEGMENT_KEY}}"];
}
- (void)showCheckoutForm {
// チェックアウトフォーム設定ロジック
}
- (void)processPayment {
// 決済処理ロジック
}
@end
結果: ユーザーがチェックアウト区間に進入する前にキューで待機し、制御された同時性を維持します。
ステップ3: 動作確認
基本コントロールの場合:
- セグメントで進入許容数を0に設定 (待合室が表示される必要がある)
- 待合室表示を確認 (予想待機時間が表示される)
- 進入許容数を1に設定 (即座に進入する必要がある)
- ログまたはネットワーク監視でキー返却を確認
区間コントロールの場合:
- セグメントで進入許容数を0に設定 (待合室が表示される必要がある)
- 待合室表示を確認 (予想待機時間が表示されない)
- 進入許容数を1に設定 (即座に区間に進入する必要がある)
- 区間を通過してナビゲート (Section1 → Section2 → End)
- ログでキータイムアウト延長を確認 (5003リクエストを探す)
- 区間が完了したらキー返却を確認
ヘルプが必要ですか?
- トラブルシューティング: 一般的な問題および解決方法
- iOSログでNetFUNNELメッセージを確認 (
printLog = trueを有効化) - プロジェクト/セグメントキーがコンソールと正確に一致することを確認