我编译了 libdispatch 。 这段代码正在运行:
String SENT = "sent";
String DELIVERED = "delivered";
Intent sentIntent = new Intent(SENT);
/*Create Pending Intents*/
PendingIntent sentPI = PendingIntent.getBroadcast(
getApplicationContext(), 0, sentIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
Intent deliveryIntent = new Intent(DELIVERED);
PendingIntent deliverPI = PendingIntent.getBroadcast(
getApplicationContext(), 0, deliveryIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
/* Register for SMS send action */
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String result = "";
switch (getResultCode()) {
case Activity.RESULT_OK:
result = "Transmission successful";
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
result = "Transmission failed";
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
result = "Radio off";
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
result = "No PDU defined";
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
result = "No service";
break;
}
Toast.makeText(getApplicationContext(), result,
Toast.LENGTH_LONG).show();
}
}, new IntentFilter(SENT));
/* Register for Delivery event */
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(getApplicationContext(), "Deliverd",
Toast.LENGTH_LONG).show();
}
}, new IntentFilter(DELIVERED));
/*Send SMS*/
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, msg, sentPI,
deliverPI);
Toast.makeText(getApplicationContext(),
ex.getMessage().toString(), Toast.LENGTH_LONG)
.show();
ex.printStackTrace();
但是如果我把这段代码放到结束文件中:
import Dispatch
var lockQueue = dispatch_queue_create("com.test.async", nil);
我收到了一个错误:
使用未解析的标识符' dispatch_async'
答案 0 :(得分:3)
正如我上面评论的那样,这似乎是a current limitation with the Swift Package Manager。它目前不支持添加适当的编译时选项,例如支持块作为GCD函数(-Xcc -fblocks
)的输入所需的选项。
与此同时,您可以避免使用Swift Package Manager并使用swiftc直接编译文件,并使用适当的选项。谢弗勒在their test repository中提供了一个例子:
swiftc -v -o gcd4 Sources/main.swift -I .build/debug -j8 -Onone -g -Xcc -fblocks -Xcc -F-module-map=Packages/CDispatch-1.0.0/module.modulemap -I Packages/CDispatch-1.0.0 -I /usr/local/include
-I
选项将为libdispatch提供模块映射,因此请调整它们以匹配实际放置这些系统模块目录的位置。