关于APPextensions开发遇到的命令总结
1.security cms -D -i /Users/niejinhao/Library/Developer/Xcode/DerivedData/AppCanPlugin-adobmibzfaxsvkebajlhltcfpqry/Build/Products/Debug-iphoneos/uexCallKit.appex/embedded.mobileprovision
2.certifierName="iPhone Developer: 金浩 聂 (AA296KGJGL)"
3.codesign -f -s $certifierName --entitlements AppCanPlugin.entitlements uexCallKit
4.certifierName="iPhone Developer: niejinhao@qq.com (S7UJ6DUK7Q)"
5.codesign -f -s $certifierName --entitlements AppCanPlugin.entitlements uexCallKit
6.codesign -f -s 'iPhone Distribution: Moving Increasingly Interconnected Technology Co., Ltd' uexCallKit
7.codesign -f -s 'iPhone Distribution: Moving Increasingly Interconnected Technology Co., Ltd' uexCallKit.appex
8.codesign -f -s 'iPhone Distribution: Moving Increasingly Interconnected Technology Co., Ltd' ./uexCallKit
9.security cms -D -i /Users/niejinhao/Desktop/证书/聂金浩/niejinhaoDistribution.mobileprovision
pwd
cp niejinhaoDistributionCallKit.mobileprovision /Library/MobileDevice/Provisioning\ Profiles/
echo niejinhao2
需要准备一个证书,两个bundle ID ,两个配置文件(bundle ID 需要开通APPGroup权限)
H5调用插件
<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link rel="stylesheet" href="css/fonts/font-awesome.min.css">
<link rel="stylesheet" href="css/ui-box.css">
<link rel="stylesheet" href="css/ui-base.css">
<link rel="stylesheet" href="css/ui-color.css">
<link rel="stylesheet" href="css/appcan.icon.css">
<link rel="stylesheet" href="css/appcan.control.css">
</head>
<body class="um-vp" ontouchstart>
<div id="page_0" class="up ub ub-ver bc-bg" tabindex="0">
<!--header开始-->
<div id="header" class="uh bc-text-head ub bc-head">
<div class="nav-btn" id="nav-left"></div>
<h1 class="ut ub-f1 ulev-3 ut-s tx-c" tabindex="0">AppCanEngineDebug</h1>
<div class="nav-btn" id="nav-right">
<!--按钮开始-->
<!--按钮结束-->
</div>
</div>
<!--header结束--><!--content开始-->
<div id="content" class="ub-f1 tx-l ">
<input class="btn" type="button" value="Test" οnclick="test();">
</div>
<!--content结束-->
</div>
</body>
<script>
function test(){
var param = {
"links": [
{
"num": "8615321375192",
"name": "骗子-信息中心-系统运营"
},
{
"num": "8615313626106",
"name": "李四-信息中心-系统运营"
},
{
"num": "8613800138000",
"name": "张三-信息中心-系统运营"
}
]
}
uexCallKit.openCallKit(param);
}
</script>
</html>
uexCallKit插件.h文件 继承EUExBase 设置.a名称 设置.a输出wei'z
//
// EUExCallKit.h
// EUExCallKit
//
// Created by niejinhao on 2017/10/18.
// Copyright © 2017年 niejinhao. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <AppCanKit/AppCanKit.h>
@interface EUExCallKit : EUExBase
@end
uexCallKit插件.m文件 两个文件配置 (1)group.bundle ID (2)com.zymobi.niejinhao.uexCallKit配置文件bundle ID
//
// EUExCallKit.m
// EUExCallKit
//
// Created by niejinhao on 2017/10/18.
// Copyright © 2017年 niejinhao. All rights reserved.
//
#import "EUExCallKit.h"
#import <CallKit/CallKit.h>
@implementation EUExCallKit
- (instancetype)initWithWebViewEngine:(id<AppCanWebViewEngineObject>)engine{
self = [super initWithWebViewEngine:engine];
if (self) {
//初始化工作
}
return self;
}
- (void)clean{
//NSLog(@"网页即将被销毁");
}
- (void)openCallKit:(NSMutableArray *)inArguments{
if([inArguments count] < 1){return;}
ACArgsUnpack(NSDictionary *infoDic) = inArguments;
if (infoDic == nil) {return;}
[self saveTextByNSFileManager:[infoDic objectForKey:@"links"]];
[self checkPermissions:nil];
}
- (BOOL)saveTextByNSFileManager:(NSArray *)arr
{
NSError *err = nil;
NSURL *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.com.zymobi.niejinhao"];
containerURL = [containerURL URLByAppendingPathComponent:@"Library/Caches/good"];
BOOL result = [arr writeToURL:containerURL atomically:YES];
if (!result) {
NSLog(@"%@",err);
} else {
NSLog(@"save success.");
}
return result;
}
-(void)checkPermissions:(UIButton *)sender
{
CXCallDirectoryManager *manager = [CXCallDirectoryManager sharedInstance];
// 获取权限状态
[manager getEnabledStatusForExtensionWithIdentifier:@"com.zymobi.niejinhao.uexCallKit" completionHandler:^(CXCallDirectoryEnabledStatus enabledStatus, NSError * _Nullable error) {
if (!error) {
NSString *title = nil;
if (enabledStatus == CXCallDirectoryEnabledStatusDisabled) {
title = @"未授权,请在设置->电话授权相关权限";
}else if (enabledStatus == CXCallDirectoryEnabledStatusEnabled) {
title = @"授权";
}else if (enabledStatus == CXCallDirectoryEnabledStatusUnknown) {
title = @"不知道";
}
NSLog(@"授权:%@",title);
}else{
NSLog(@"授权:失败");
}
[self updateData:nil];
}];
}
-(void)updateData:(UIButton *)sender
{
CXCallDirectoryManager *manager = [CXCallDirectoryManager sharedInstance];
[manager reloadExtensionWithIdentifier:@"com.zymobi.niejinhao.uexCallKit" completionHandler:^(NSError * _Nullable error) {
if (error == nil) {
NSLog(@"更新成功");
}else{
NSLog(@"更新失败");
}
}];
}
@end
//
// CallDirectoryHandler.h
// uexCallKit
//
// Created by niejinhao on 2017/10/23.
// Copyright © 2017年 zywx. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CallKit/CallKit.h>
@interface CallDirectoryHandler : CXCallDirectoryProvider
@end
//
// CallDirectoryHandler.m
// uexCallKit
//
// Created by niejinhao on 2017/10/19.
// Copyright © 2017年 zywx. All rights reserved.
//
#import "CallDirectoryHandler.h"
@interface CallDirectoryHandler () <CXCallDirectoryExtensionContextDelegate>
@end
@implementation CallDirectoryHandler
- (void)beginRequestWithExtensionContext:(CXCallDirectoryExtensionContext *)context {
context.delegate = self;
if (![self addBlockingPhoneNumbersToContext:context]) {
NSLog(@"Unable to add blocking phone numbers");
NSError *error = [NSError errorWithDomain:@"CallDirectoryHandler" code:1 userInfo:nil];
[context cancelRequestWithError:error];
return;
}
if (![self addIdentificationPhoneNumbersToContext:context]) {
NSLog(@"Unable to add identification phone numbers");
NSError *error = [NSError errorWithDomain:@"CallDirectoryHandler" code:2 userInfo:nil];
[context cancelRequestWithError:error];
return;
}
[context completeRequestWithCompletionHandler:nil];
}
- (BOOL)addBlockingPhoneNumbersToContext:(CXCallDirectoryExtensionContext *)context {
// Retrieve phone numbers to block from data store. For optimal performance and memory usage when there are many phone numbers,
// consider only loading a subset of numbers at a given time and using autorelease pool(s) to release objects allocated during each batch of numbers which are loaded.
//
// Numbers must be provided in numerically ascending order.
CXCallDirectoryPhoneNumber phoneNumbers[] = { 14085555555, 18005555555 };
NSUInteger count = (sizeof(phoneNumbers) / sizeof(CXCallDirectoryPhoneNumber));
for (NSUInteger index = 0; index < count; index += 1) {
CXCallDirectoryPhoneNumber phoneNumber = phoneNumbers[index];
[context addBlockingEntryWithNextSequentialPhoneNumber:phoneNumber];
}
return YES;
}
- (BOOL)addIdentificationPhoneNumbersToContext:(CXCallDirectoryExtensionContext *)context {
// Retrieve phone numbers to identify and their identification labels from data store. For optimal performance and memory usage when there are many phone numbers,
// consider only loading a subset of numbers at a given time and using autorelease pool(s) to release objects allocated during each batch of numbers which are loaded.
//
// Numbers must be provided in numerically ascending order.
//(1)升序 (2)86+number (3)一对一关系 (4)取值
NSArray *arr = [self readTextByNSFileManager];
NSArray *result = [arr sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
return [[obj1 objectForKey:@"num"] compare:[obj2 objectForKey:@"num"]]; //升序
}];
for (NSUInteger i = 0; i < [result count]; i += 1) {
CXCallDirectoryPhoneNumber phoneNumber = [[result[i] objectForKey:@"num"] longLongValue];
NSString *label = [result[i] objectForKey:@"name"];
[context addIdentificationEntryWithNextSequentialPhoneNumber:phoneNumber label:label];
}
return YES;
}
#pragma mark - activity
- (NSArray *)readTextByNSFileManager
{
NSURL *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.com.zymobi.niejinhao"];
containerURL = [containerURL URLByAppendingPathComponent:@"Library/Caches/good"];
NSArray *Arr = [NSArray arrayWithContentsOfURL:containerURL];
return Arr;
}
#pragma mark - CXCallDirectoryExtensionContextDelegate
- (void)requestFailedForExtensionContext:(CXCallDirectoryExtensionContext *)extensionContext withError:(NSError *)error {
// An error occurred while adding blocking or identification entries, check the NSError for details.
// For Call Directory error codes, see the CXErrorCodeCallDirectoryManagerError enum in <CallKit/CXError.h>.
//
// This may be used to store the error details in a location accessible by the extension's containing app, so that the
// app may be notified about errors which occured while loading data even if the request to load data was initiated by
// the user in Settings instead of via the app itself.
}
@end
1.需要更换uexCallKit.appex 中证书签名和plist文件中bundle id;
2. 在appCan中加入描述文件
pwd
rm /Library/MobileDevice/Provisioning\ Profiles/comzhejzymobileprovisionCallKit.mobileprovision
cp comzhejzymobileprovisionCallKit.mobileprovision /Library/MobileDevice/Provisioning\ Profiles/c17ee14f-5677-417f-a20e-4adc66b9ebee.mobileprovision
cd /Library/MobileDevice/Provisioning\ Profiles/
ls -l
security cms -D -i c17ee14f-5677-417f-a20e-4adc66b9ebee.mobileprovision
echo niejinhao2