URLスキームでTextFieldの値を渡し、相手のアプリのLabelに表示するところまで確認しました。
試してみてください。
呼び出す側
ViewController.m
Objective
1#import "ViewController.h"
2
3@interface ViewController ()
4// テキストフィールド
5@property (weak, nonatomic) IBOutlet UITextField *myTextField;
6@end
7
8@implementation ViewController
9
10- (IBAction)pushSchemeButton {
11
12 NSString *schemeName = @"Scheme";
13 NSString *text = _myTextField.text;
14
15 // URLスキームでアプリを呼び出す(TextFieldの文字列を渡す)
16 NSString *url = [NSString stringWithFormat:@"%@://%@", schemeName, text];
17 BOOL canOpen = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:url]];
18 if (canOpen) {
19 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
20 }
21}
22@end
呼び出される側
AppDelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) NSString *schemeMessage;
@end
AppDelegate.m
objective
1#import "AppDelegate.h"
2
3@implementation AppDelegate
4
5- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
6 return YES;
7}
8
9- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
10
11 self.schemeMessage = [url host];
12 return YES;
13}
14
15@end
ViewController.m
objective
1#import "ViewController.h"
2#import "AppDelegate.h"
3
4@interface ViewController ()
5
6// 表示する為のラベル
7@property (weak, nonatomic) IBOutlet UILabel *label;
8
9@end
10
11@implementation ViewController
12
13- (void)viewWillAppear:(BOOL)animated {
14 [super viewWillAppear:animated];
15
16 // ラベルにTextを設定
17 AppDelegate *appDelegete = [[UIApplication sharedApplication] delegate];
18 self.label.text = appDelegete.schemeMessage;
19}
20@end
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/27 06:02