質問編集履歴

1

コードを追加

2017/03/22 14:02

投稿

wine
wine

スコア18

test CHANGED
File without changes
test CHANGED
@@ -2,8 +2,86 @@
2
2
 
3
3
 
4
4
 
5
+ AppDelegate.swift の一部
6
+
5
7
  ```swift
6
8
 
9
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
10
+
11
+ // APNs
12
+
13
+ UNUserNotificationCenter.current().requestAuthorization(
14
+
15
+ options: [.badge, .alert, .sound]) {(accepted, error) in
16
+
17
+ if accepted {
18
+
19
+ print("Notification access accepted !")
20
+
21
+
22
+
23
+ // デバイストークンを登録
24
+
25
+ UIApplication.shared.registerForRemoteNotifications()
26
+
27
+ }
28
+
29
+ else{
30
+
31
+ print("Notification access denied.")
32
+
33
+ }
34
+
35
+ }
36
+
37
+ return true
38
+
39
+ }
40
+
41
+
42
+
43
+ // Remote Notification のエラーを受け取る
44
+
45
+ func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
46
+
47
+ print(error)
48
+
49
+ }
50
+
51
+
52
+
53
+ // Remote Notification の device token を表示
54
+
55
+ func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
56
+
57
+
58
+
59
+ var deviceToken = String(format: "%@", deviceToken as CVarArg) as String//トークン原型取得
60
+
61
+ print("DeviceToken = \(deviceToken)")
62
+
63
+ // < > を外す
64
+
65
+ let characterSet: CharacterSet = CharacterSet.init(charactersIn: "<>")
66
+
67
+ deviceToken = deviceToken.trimmingCharacters(in: characterSet)
68
+
69
+ // スペースを除去
70
+
71
+ deviceToken = deviceToken.replacingOccurrences(of: " ", with: "")
72
+
73
+
74
+
75
+ sendToken(token: deviceToken)//送信
76
+
77
+
78
+
79
+ print("deviceToken = \(deviceToken)")
80
+
81
+ }
82
+
83
+
84
+
7
85
  // POST 送信
8
86
 
9
87
  func sendToken(token: String){
@@ -82,16 +160,14 @@
82
160
 
83
161
  ```
84
162
 
163
+ Xcodeのログ
164
+
85
- ```
165
+ ```
86
-
87
- xcodeログ
88
166
 
89
167
  Notification access accepted !
90
168
 
91
169
  deviceToken = <hogehoge hogehoge hogehoge hogehoge hogehoge hogehoge hogehoge hogehoge>
92
170
 
93
- token sousin!!!!!!
94
-
95
171
  deviceToken = 8hogehogehogehoge
96
172
 
97
173
  response: <NSHTTPURLResponse: 0x17002e4a0> { URL: http://ec2-hoge.compute.amazonaws.com/get_device_token.php } { status code: 200, headers {
@@ -120,8 +196,16 @@
120
196
 
121
197
 
122
198
 
123
- httpステータスは200なので、device_token.html作成されechoも返ってきません。
199
+ アプリを起動るとPOST通信して、device_token.html作成されると思ったのですが作成されません。
200
+
201
+
202
+
124
-
203
+ また、echoがXcodeのログに返ってくると思っていたのですが、それも返ってきません。
204
+
205
+
206
+
125
-
207
+ ファイルを置き、POSTするだけでは、phpが実行されないのでしょうか?
126
-
208
+
209
+
210
+
127
- 心者なため、初歩的なミス・勘違いかもしれませんが、よろしくお願いいたします
211
+ 初歩的なミス・勘違いかもしれませんが、よろしくお願いいたします