我想实现一个imessage应用程序,但是对于消息框架是新手,而iMessage应用程序是一个新事物,资源并不多。所以我关注WWDC video并使用提供sample app的苹果作为指南。
我有三个视图,#!/usr/bin/env python
from __future__ import print_function
from timeit import Timer
mylist = "99.916667,100,99.983333,99.983333,99.233333,99.933333,99.95,99.9,99.9,99.066667,99.933333,99.966667,99.966667,99.866667,99.316667,99.883333,99.9,99.983333,99.85,98.7,99.933333,99.95,99.983333,100,99.05,100,99.866667,99.983333,99.933333,99.883333,99.983333,100,99.983333,99.983333,99.95,100,98.5,99.983333,99.45,108.925926,99.5,99.983333,100,99.966667,98.366667,99.983333,99.983333,91.516667,99.283333,99.65,99.933333,99.983333,99.933333,99.95,99.75,99.966667,99.733333,99.966667,100,99.75,99.916667,100,99.983333,99.983333,99.233333,99.933333,99.95,99.9,99.9,99.066667,99.933333,99.966667,99.966667,99.866667,99.316667,99.883333,99.9,99.983333,99.85,98.7,99.933333,99.95,99.983333,100,99.05,100,99.866667,99.983333,99.933333,99.883333,99.983333,100,99.983333,99.983333,99.95,100,98.5,99.983333,99.45,108.925926,99.5,99.983333,100,99.966667,98.366667,99.983333,99.983333,91.516667,99.283333,99.65,99.933333,99.983333,99.933333,99.95,99.75,99.966667,99.733333,99.966667,100,99.75,99.916667,100,99.983333,99.983333,99.233333,99.933333,99.95,99.9,99.9,99.066667,99.933333,99.966667,99.966667,99.866667,99.316667,99.883333,99.9,99.983333,99.85,98.7,99.933333,99.95,99.983333,100,99.05,100,99.866667,99.983333,99.933333,99.883333,99.983333,100,99.983333,99.983333,99.95,100,98.5,99.983333,99.45,108.925926,99.5,99.983333,100,99.966667,98.366667,99.983333,99.983333,91.516667,99.283333,99.65,99.933333,99.983333,99.933333,99.95,99.75,99.966667,99.733333,99.966667,100,99.75,99.916667,100,99.983333,99.983333,99.233333,99.933333,99.95,99.9,99.9,99.066667,99.933333,99.966667,99.966667,99.866667,99.316667,99.883333,99.9,99.983333,99.85,98.7,99.933333,99.95,99.983333,100,99.05,100,99.866667,99.983333,99.933333,99.883333,99.983333,100,99.983333,99.983333,99.95,100,98.5,99.983333,99.45,108.925926,99.5,99.983333,100,99.966667,98.366667,99.983333,99.983333,91.516667,99.283333,99.65,99.933333,99.983333,99.933333,99.95,99.75,99.966667,99.733333,99.966667,100,99.75,99.916667,100,99.983333,99.983333,99.233333,99.933333,99.95,99.9,99.9,99.066667,99.933333,99.966667,99.966667,99.866667,99.316667,99.883333,99.9,99.983333,99.85,98.7,99.933333,99.95,99.983333,100,99.05,100,99.866667,99.983333,99.933333,99.883333,99.983333,100,99.983333,99.983333,99.95,100,98.5,99.983333,99.45,108.925926,99.5,99.983333,100,99.966667,98.366667,99.983333,99.983333,91.516667,99.283333,99.65,99.933333,99.983333,99.933333,99.95,99.75,99.966667,99.733333,99.966667,100,99.75,99.916667,100,99.983333,99.983333,99.233333,99.933333,99.95,99.9,99.9,99.066667,99.933333,99.966667,99.966667,99.866667,99.316667,99.883333,99.9,99.983333,99.85,98.7,99.933333,99.95,99.983333,100,99.05,100,99.866667,99.983333,99.933333,99.883333,99.983333,100,99.983333,99.983333,99.95,100,98.5,99.983333,99.45,108.925926,99.5,99.983333,100,99.966667,98.366667,99.983333,99.983333,91.516667,99.283333,99.65,99.933333,99.983333,99.933333,99.95,99.75,99.966667,99.733333,99.966667,100,99.75,99.916667,100,99.983333,99.983333,99.233333,99.933333,99.95,99.9,99.9,99.066667,99.933333,99.966667,99.966667,99.866667,99.316667,99.883333,99.9,99.983333,99.85,98.7,99.933333,99.95,99.983333,100,99.05,100,99.866667,99.983333,99.933333,99.883333,99.983333,100,99.983333,99.983333,99.95,100,98.5,99.983333,99.45,108.925926,99.5,99.983333,100,99.966667,98.366667,99.983333,99.983333,91.516667,99.283333,99.65,99.933333,99.983333,99.933333,99.95,99.75,99.966667,99.733333,99.966667,100,99.75,99.916667,100,99.983333,99.983333,99.233333,99.933333,99.95,99.9,99.9,99.066667,99.933333,99.966667,99.966667,99.866667,99.316667,99.883333,99.9,99.983333,99.85,98.7,99.933333,99.95,99.983333,100,99.05,100,99.866667,99.983333,99.933333,99.883333,99.983333,100,99.983333,99.983333,99.95,100,98.5,99.983333,99.45,108.925926,99.5,99.983333,100,99.966667,98.366667,99.983333,99.983333,91.516667,99.283333,99.65,99.933333,99.983333,99.933333,99.95,99.75,99.966667,99.733333,99.966667,100,99.75,99.916667,100,99.983333,99.983333,99.233333,99.933333,99.95,99.9,99.9,99.066667,99.933333,99.966667,99.966667,99.866667,99.316667,99.883333,99.9,99.983333,99.85,98.7,99.933333,99.95,99.983333,100,99.05,100,99.866667,99.983333,99.933333,99.883333,99.983333,100,99.983333,99.983333,99.95,100,98.5,99.983333,99.45,108.925926,99.5,99.983333,100,99.966667,98.366667,99.983333,99.983333,91.516667,99.283333,99.65,99.933333,99.983333,99.933333,99.95,99.75,99.966667,99.733333,99.966667,100,99.75,99.916667,100,99.983333,99.983333,99.233333,99.933333,99.95,99.9,99.9,99.066667,99.933333,99.966667,99.966667,99.866667,99.316667,99.883333,99.9,99.983333,99.85,98.7,99.933333,99.95,99.983333,100,99.05,100,99.866667,99.983333,99.933333,99.883333,99.983333,100,99.983333,99.983333,99.95,100,98.5,99.983333,99.45,108.925926,99.5,99.983333,100,99.966667,98.366667,99.983333,99.983333,91.516667,99.283333,99.65,99.933333,99.983333,99.933333,99.95,99.75,99.966667,99.733333,99.966667,100,99.75,99.916667,100,99.983333,99.983333,99.233333,99.933333,99.95,99.9,99.9,99.066667,99.933333,99.966667,99.966667,99.866667,99.316667,99.883333,99.9,99.983333,99.85,98.7,99.933333,99.95,99.983333,100,99.05,100,99.866667,99.983333,99.933333,99.883333,99.983333,100,99.983333,99.983333,99.95,100,98.5,99.983333,99.45,108.925926,99.5,99.983333,100,99.966667,98.366667,99.983333,99.983333,91.516667,99.283333,99.65,99.933333,99.983333,99.933333,99.95,99.75,99.966667,99.733333,99.966667,100,99.75,99.916667,100,99.983333,99.983333,99.233333,99.933333,99.95,99.9,99.9,99.066667,99.933333,99.966667,99.966667,99.866667,99.316667,99.883333,99.9,99.983333,99.85,98.7,99.933333,99.95,99.983333,100,99.05,100,99.866667,99.983333,99.933333,99.883333,99.983333,100,99.983333,99.983333,99.95,100,98.5,99.983333,99.45,108.925926,99.5,99.983333,100,99.966667,98.366667,99.983333,99.983333,91.516667,99.283333,99.65,99.933333,99.983333,99.933333,99.95,99.75,99.966667,99.733333,99.966667,100,99.75,99.916667,100,99.983333,99.983333,99.233333,99.933333,99.95,99.9,99.9,99.066667,99.933333,99.966667,99.966667,99.866667,99.316667,99.883333,99.9,99.983333,99.85,98.7,99.933333,99.95,99.983333,100,99.05,100,99.866667,99.983333,99.933333,99.883333,99.983333,100,99.983333,99.983333,99.95,100,98.5,99.983333,99.45,108.925926,99.5,99.983333,100,99.966667,98.366667,99.983333,99.983333,91.516667,99.283333,99.65,99.933333,99.983333,99.933333,99.95,99.75,99.966667,99.733333,99.966667,100,99.75,99.916667,100,99.983333,99.983333,99.233333,99.933333,99.95,99.9,99.9,99.066667,99.933333,99.966667,99.966667,99.866667,99.316667,99.883333,99.9,99.983333,99.85,98.7,99.933333,99.95,99.983333,100,99.05,100,99.866667,99.983333,99.933333,99.883333,99.983333,100,99.983333,99.983333,99.95,100,98.5,99.983333,99.45,108.925926,99.5,99.983333,100,99.966667,98.366667,99.983333,99.983333,91.516667,99.283333,99.65,99.933333,99.983333,99.933333,99.95,99.75,99.966667,99.733333,99.966667,100,99.75,99.916667,100,99.983333,99.983333,99.233333,99.933333,99.95,99.9,99.9,99.066667,99.933333,99.966667,99.966667,99.866667,99.316667,99.883333,99.9,99.983333,99.85,98.7,99.933333,99.95,99.983333,100,99.05,100,99.866667,99.983333,99.933333,99.883333,99.983333,100,99.983333,99.983333,99.95,100,98.5,99.983333,99.45,108.925926,99.5,99.983333,100,99.966667,98.366667,99.983333,99.983333,91.516667,99.283333,99.65,99.933333,99.983333,99.933333,99.95,99.75,99.966667,99.733333,99.966667,100,99.75,99.916667,100,99.983333,99.983333,99.233333,99.933333,99.95,99.9,99.9,99.066667,99.933333,99.966667,99.966667,99.866667,99.316667,99.883333,99.9,99.983333,99.85,98.7,99.933333,99.95,99.983333,100,99.05,100,99.866667,99.983333,99.933333,99.883333,99.983333,100,99.983333,99.983333,99.95,100,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,-89.955946,98.5,99.983333,99.45,108.925926,99.5,99.983333,100,99.966667,98.366667,99.983333,99.983333,91.516667,99.283333,99.65,99.933333,99.983333,99.933333,99.95,99.75,99.966667,99.733333,99.966667,100,99.75,99.916667,100,99.983333,99.983333,99.233333,99.933333,99.95,99.9,99.9,99.066667,99.933333,99.966667,99.966667,99.866667,99.316667,99.883333,99.9,99.983333,99.85,98.7,99.933333,99.95,99.983333,100,99.05,100,99.866667,99.983333,99.933333,99.883333,99.983333,100,99.983333,99.983333,99.95,100,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null"
float_list = []
def tryway():
float_list = []
mysplitlist = mylist.split(",")
for string in mysplitlist:
try:
myfloat = float(string)
float_list.append(myfloat)
except ValueError:
if string == 'null':
pass
else:
raise ValueError
#print(float_list)
def ifway():
float_list = []
mysplitlist = mylist.split(",")
for string in mysplitlist:
try:
if string != "null":
myfloat = float(string)
float_list.append(myfloat)
except:
raise
#print(float_list)
if __name__ == '__main__':
print("Testing Try")
tr = Timer("tryway()","from __main__ import tryway")
print(tr.timeit(1000))
print("Testing If")
ir = Timer("ifway()","from __main__ import ifway")
print(ir.timeit(1000))
处理几乎所有功能,然后是$ ./test_try_if.py
Testing Try
2.23783922195
Testing If
0.631629943848
和MessageViewController
。
我只是尝试从CreateViewController
创建DetailsViewController
并显示在MSMessage
..然后添加到数据中。
但是我在尝试创建数据时遇到了崩溃。
CreateViewController
我试图传递的数据类型是结构中的字典:
DetailsViewController
所以这里是如何建立的;
MessagesViewController
@IBAction func createAction(_ sender: AnyObject) {
//present full screen for create list
self.delegate?.createViewControllerDidSelectAdd(self as! CreateViewControllerDelegate)
}
CreateViewController
struct data {
var title: String!
var date: Date!
var dictionary = ["title" : String(), "Array1" : [String](), "Array2" : [String]() ] as [String : Any]
}
有人会显示我出错的地方以及如何发送class MessagesViewController: MSMessagesAppViewController, {
// MARK: Responsible for create list button
func composeMessage(for data: dataItem) {
let messageCaption = NSLocalizedString("Let's make", comment: "")
let dictionary = data.dictionary
func queryItems(dictionary: [String:String]) -> [URLQueryItem] {
return dictionary.map {
URLQueryItem(name: $0, value: $1)
}
}
var components = URLComponents()
components.queryItems = queryItems(dictionary: dictionary as! [String : String])
let layout = MSMessageTemplateLayout()
layout.image = UIImage(named: "messages-layout-1.png")!
layout.caption = messageCaption
let message = MSMessage()
message.url = components.url!
message.layout = layout
message.accessibilityLabel = messageCaption
guard let conversation = activeConversation else { fatalError("Expected Convo") }
conversation.insert(message) { error in
if let error = error {
print(error)
}
}
}
}
extension MessagesViewController: CreateViewControllerDelegate {
func createViewControllerDidSelectAdd(_ controller: CreateViewControllerDelegate) {
//CreatesNewDataItem
composeMessage(for: dataItem())
}
}
吗?如果我能够发送消息,那么我应该能够接收和重新发送。
答案 0 :(得分:0)
我看到一个问题,我自己无法调试: 您将components.queryItems设置为您的字典var cast为[String:String],但从data.dictionary返回的字典不是[String:String],而是[String:Any]
特别是,dictionary [“Array1”]是一个字符串数组,而不是一个字符串。对于字典[“Array2”]也是如此。 URLQueryItem期望在其init()中给出两个字符串,但是你试图放入一个字符串和一个字符串数组(虽然我不确定你是否真的在queryItems中找到那一行(字典:方法。
当然,您的dataItem.dictionary返回一个包含4个空值的字典。我不确定那是你想要的。