我正在为xamarin表单项目开发Apple watch伴侣应用程序。当iPhone应用程序或父应用程序处于后台时,我无法从父应用程序获取连续数据到我的配套应用程序。我在app委托中使用了以下代码的和平,但由于iOS后台时间限制为10分钟,因此也会在一定时间后停止发送数据。 有些机构可以建议,即使父应用程序处于后台,也可以从父应用程序连续获取数据的正确方法。
# I generate some fake data to mimic your problem
set.seed(125)
library(igraph)
# fake df1
df1 <- data.frame(ID = 1:9, dept = rep(LETTERS[1:3], 3), stringsAsFactors = F)
df1
#> ID dept
#> 1 1 A
#> 2 2 B
#> 3 3 C
#> 4 4 A
#> 5 5 B
#> 6 6 C
#> 7 7 A
#> 8 8 B
#> 9 9 C
# fake df2
df2 <- data.frame(sender = sample(1:9, 6, replace = T), receiver = sample(1:9, 6, replace = T))
df2
#> sender receiver
#> 1 8 5
#> 2 2 3
#> 3 3 6
#> 4 4 6
#> 5 9 1
#> 6 9 7
# the graph
g <- graph_from_data_frame(df2)
# You can get your general approach to work
# if the department codes are a named vector,
# where the names are the IDs. If this is the case
# a call like dept[c(ID1, ID3, ID2)] will ouput the
# department of individual 1, 3 and 2 in that order
named.dept <- df1$dept
names(named.dept) <- df1$ID
# To see how it works
named.dept[df2$sender]
#> 8 2 3 4 9 9
#> "B" "B" "C" "A" "C" "C"
# Now using your code
E(g)$internal <- as.numeric(named.dept[df2$sender] == named.dept[df2$receiver])
E(g)$internal
#> [1] 1 0 1 0 0 0