回答編集履歴
4
ログ追加。
test
CHANGED
@@ -108,21 +108,45 @@
|
|
108
108
|
|
109
109
|
```
|
110
110
|
|
111
|
-
2016-10-19 19:48:46
|
111
|
+
2016-10-19 19:48:46 test[8916] persistentID=1294602247482248857
|
112
112
|
|
113
|
-
2016-10-19 19:48:46
|
113
|
+
2016-10-19 19:48:46 test[8916] 2016-10-19 10:30:22 +0000 [The Miracle (Of Joey Ramone)] [Songs of Innocence] [U2] 255.382000
|
114
114
|
|
115
115
|
|
116
116
|
|
117
|
-
2016-10-19 20:00:39
|
117
|
+
2016-10-19 20:00:39 test[8916] persistentID=1294602247482248854
|
118
118
|
|
119
|
-
2016-10-19 20:00:39
|
119
|
+
2016-10-19 20:00:39 test[8916] 2016-10-19 10:54:55 +0000 [Every Breaking Wave] [Songs of Innocence] [U2] 252.162000
|
120
120
|
|
121
|
-
2016-10-19 20:00:39
|
121
|
+
2016-10-19 20:00:39 test[8916] [fetch]
|
122
122
|
|
123
|
-
2016-10-19 20:00:39
|
123
|
+
2016-10-19 20:00:39 test[8916] persistentID=1294602247482248852
|
124
124
|
|
125
|
-
2016-10-19 20:00:39
|
125
|
+
2016-10-19 20:00:39 test[8916] 2016-10-19 10:58:55 +0000 [California (There Is No End to Love)] [Songs of Innocence] [U2] 239.846000
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
2016-10-19 20:23:17 test[8916] persistentID=1294602247482248855
|
130
|
+
|
131
|
+
2016-10-19 20:23:17 test[8916] 2016-10-19 11:02:41 +0000 [Song for Someone] [Songs of Innocence] [U2] 226.763000
|
132
|
+
|
133
|
+
2016-10-19 20:23:17 test[8916] [fetch]
|
134
|
+
|
135
|
+
2016-10-19 20:23:17 test[8916] persistentID=1294602247482248860
|
136
|
+
|
137
|
+
2016-10-19 20:23:17 test[8916] 2016-10-19 11:08:01 +0000 [Iris (Hold Me Close)] [Songs of Innocence] [U2] 319.457000
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
2016-10-19 20:32:18 test[8916] persistentID=1294602247482248862
|
142
|
+
|
143
|
+
2016-10-19 20:32:18 test[8916] 2016-10-19 11:29:52 +0000 [This Is Where You Can Reach Me Now] [Songs of Innocence] [U2] 305.134000
|
144
|
+
|
145
|
+
2016-10-19 20:32:18 test[8916] [fetch]
|
146
|
+
|
147
|
+
2016-10-19 20:32:18 test[8916] persistentID=1294602247482248861
|
148
|
+
|
149
|
+
2016-10-19 20:32:18 test[8916] 2016-10-18 01:15:35 +0000 [The Troubles] [Songs of Innocence] [U2] 285.843000
|
126
150
|
|
127
151
|
```
|
128
152
|
|
3
persistentID
test
CHANGED
@@ -58,21 +58,41 @@
|
|
58
58
|
|
59
59
|
{
|
60
60
|
|
61
|
+
MPMediaEntityPersistentID persistentID = [notif.userInfo[@"MPMusicPlayerControllerNowPlayingItemPersistentIDKey"] unsignedLongLongValue];
|
62
|
+
|
61
|
-
|
63
|
+
NSLog(@"persistentID=%llu", persistentID);
|
62
64
|
|
63
65
|
|
64
66
|
|
65
|
-
MPMedia
|
67
|
+
MPMediaQuery *query = [MPMediaQuery new];
|
66
68
|
|
67
|
-
MPMedia
|
69
|
+
MPMediaPropertyPredicate *pred = [MPMediaPropertyPredicate predicateWithValue:@(persistentID)
|
68
70
|
|
69
|
-
|
71
|
+
forProperty:MPMediaItemPropertyPersistentID
|
70
72
|
|
71
|
-
|
73
|
+
comparisonType:MPMediaPredicateComparisonEqualTo];
|
72
74
|
|
73
|
-
|
75
|
+
[query addFilterPredicate:pred];
|
74
76
|
|
77
|
+
NSArray<MPMediaItem *> *items = [query items];
|
78
|
+
|
79
|
+
//NSLog(@"items=%@", items);
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
[items enumerateObjectsUsingBlock:^(MPMediaItem *item, NSUInteger idx, BOOL *stop) {
|
84
|
+
|
85
|
+
MPMediaType mediaType = [[item valueForProperty:MPMediaItemPropertyMediaType] unsignedIntegerValue];
|
86
|
+
|
87
|
+
if (mediaType == MPMediaTypeMusic)
|
88
|
+
|
89
|
+
{
|
90
|
+
|
91
|
+
NSLog(@"%@ [%@] [%@] [%@] %f", item.lastPlayedDate, item.title, item.albumTitle, item.artist, item.playbackDuration);
|
92
|
+
|
75
|
-
}
|
93
|
+
}
|
94
|
+
|
95
|
+
}];
|
76
96
|
|
77
97
|
}
|
78
98
|
|
@@ -82,38 +102,32 @@
|
|
82
102
|
|
83
103
|
performFetchWithCompletionHandlerの中ではNSLogを空撃ちしているだけです。
|
84
104
|
|
85
|
-
これでしばらく放置してみた
|
105
|
+
これでしばらく放置してみました。
|
86
106
|
|
87
107
|
|
88
108
|
|
89
109
|
```
|
90
110
|
|
111
|
+
2016-10-19 19:48:46.094 test[8916:596078] persistentID=1294602247482248857
|
112
|
+
|
91
|
-
2016-10-19 1
|
113
|
+
2016-10-19 19:48:46.128 test[8916:596078] 2016-10-19 10:30:22 +0000 [The Miracle (Of Joey Ramone)] [Songs of Innocence] [U2] 255.382000
|
92
114
|
|
93
115
|
|
94
116
|
|
95
|
-
2016-10-19
|
117
|
+
2016-10-19 20:00:39.437 test[8916:596078] persistentID=1294602247482248854
|
96
118
|
|
97
|
-
2016-10-19
|
119
|
+
2016-10-19 20:00:39.446 test[8916:596078] 2016-10-19 10:54:55 +0000 [Every Breaking Wave] [Songs of Innocence] [U2] 252.162000
|
98
120
|
|
99
|
-
2016-10-19
|
121
|
+
2016-10-19 20:00:39.453 test[8916:596078] [fetch]
|
100
122
|
|
101
|
-
2016-10-19
|
123
|
+
2016-10-19 20:00:39.519 test[8916:596078] persistentID=1294602247482248852
|
102
124
|
|
103
|
-
|
104
|
-
|
105
|
-
2016-10-19
|
125
|
+
2016-10-19 20:00:39.550 test[8916:596078] 2016-10-19 10:58:55 +0000 [California (There Is No End to Love)] [Songs of Innocence] [U2] 239.846000
|
106
|
-
|
107
|
-
2016-10-19 19:15:49.379 test[8721:583559] 2016-10-19 09:20:11 +0000 [Every Breaking Wave] [Songs of Innocence] [U2] 252.162000
|
108
|
-
|
109
|
-
2016-10-19 19:15:49.383 test[8721:583559] [fetch]
|
110
126
|
|
111
127
|
```
|
112
128
|
|
113
129
|
|
114
130
|
|
115
|
-
* `.lastPlayedDate`がよく分かりません。その曲を最後に再生「し切った」日時でしょうか?
|
116
|
-
|
117
|
-
|
131
|
+
うまくいってる?
|
118
132
|
|
119
133
|
|
2
間違えてた。
test
CHANGED
@@ -114,10 +114,6 @@
|
|
114
114
|
|
115
115
|
* `.lastPlayedDate`がよく分かりません。その曲を最後に再生「し切った」日時でしょうか?
|
116
116
|
|
117
|
-
* 同じ曲の通知がダブってる
|
117
|
+
* 同じ曲の通知がダブってるのは、playerから取得しているため。(修正中)
|
118
118
|
|
119
119
|
|
120
|
-
|
121
|
-
という状況で、今のところダメな感じです。
|
122
|
-
|
123
|
-
|
1
BackgroundFetch \+ Notification
test
CHANGED
@@ -21,3 +21,103 @@
|
|
21
21
|
2016-10-18 10:48:45.250 test[3519:254771] not playing
|
22
22
|
|
23
23
|
```
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
# BackgroundFetch + Notification
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
うっかりObjective-Cで書いてしまいました。
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
```objectivec
|
36
|
+
|
37
|
+
- (void)initNotif
|
38
|
+
|
39
|
+
{
|
40
|
+
|
41
|
+
MPMusicPlayerController *player = [MPMusicPlayerController systemMusicPlayer];
|
42
|
+
|
43
|
+
[[NSNotificationCenter defaultCenter] addObserver:self
|
44
|
+
|
45
|
+
selector:@selector(nowPlayingItemDidChange:)
|
46
|
+
|
47
|
+
name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification
|
48
|
+
|
49
|
+
object:player];
|
50
|
+
|
51
|
+
[player beginGeneratingPlaybackNotifications];
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
- (void)nowPlayingItemDidChange:(NSNotification *)notif
|
58
|
+
|
59
|
+
{
|
60
|
+
|
61
|
+
MPMusicPlayerController *player = notif.object;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
MPMediaItem *mediaItem = [player nowPlayingItem];
|
66
|
+
|
67
|
+
MPMediaType mediaType = [[mediaItem valueForProperty:MPMediaItemPropertyMediaType] unsignedIntegerValue];
|
68
|
+
|
69
|
+
if (mediaType == MPMediaTypeMusic)
|
70
|
+
|
71
|
+
{
|
72
|
+
|
73
|
+
NSLog(@"%@ [%@] [%@] [%@] %f", mediaItem.lastPlayedDate, mediaItem.title, mediaItem.albumTitle, mediaItem.artist, mediaItem.playbackDuration);
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
performFetchWithCompletionHandlerの中ではNSLogを空撃ちしているだけです。
|
84
|
+
|
85
|
+
これでしばらく放置してみたのですが、
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
2016-10-19 18:47:14.087 test[8721:583559] 2016-10-18 00:41:31 +0000 [Sleep Like a Baby Tonight] [Songs of Innocence] [U2] 301.641000
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
2016-10-19 18:59:35.088 test[8721:583559] 2016-10-19 09:24:10 +0000 [California (There Is No End to Love)] [Songs of Innocence] [U2] 239.846000
|
96
|
+
|
97
|
+
2016-10-19 18:59:35.142 test[8721:583559] 2016-10-19 09:24:10 +0000 [California (There Is No End to Love)] [Songs of Innocence] [U2] 239.846000
|
98
|
+
|
99
|
+
2016-10-19 18:59:35.145 test[8721:583559] 2016-10-19 09:24:10 +0000 [California (There Is No End to Love)] [Songs of Innocence] [U2] 239.846000
|
100
|
+
|
101
|
+
2016-10-19 18:59:35.151 test[8721:583559] [fetch]
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
2016-10-19 19:15:49.376 test[8721:583559] 2016-10-19 09:20:11 +0000 [Every Breaking Wave] [Songs of Innocence] [U2] 252.162000
|
106
|
+
|
107
|
+
2016-10-19 19:15:49.379 test[8721:583559] 2016-10-19 09:20:11 +0000 [Every Breaking Wave] [Songs of Innocence] [U2] 252.162000
|
108
|
+
|
109
|
+
2016-10-19 19:15:49.383 test[8721:583559] [fetch]
|
110
|
+
|
111
|
+
```
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
* `.lastPlayedDate`がよく分かりません。その曲を最後に再生「し切った」日時でしょうか?
|
116
|
+
|
117
|
+
* 同じ曲の通知がダブってる。曲毎に通知は発行されているけど、中身の情報は、通知の発行時ではなく受信時の曲情報になっている?
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
という状況で、今のところダメな感じです。
|
122
|
+
|
123
|
+
|