iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1

接入jpush-ios-3.0.8-release版本SDK之后,运行报错:

did Fail To Register For Remote Notifications With Error: Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environment”的授权字符串" UserInfo={NSLocalizedDescription=未找到应用程序的“aps-environment”的授权字符串}

Not get deviceToken yet.

 Maybe: your certificatenotconfigured APNs?

orcurrent network isnotso good so APNs registration failed?

orthere is no APNsregistercode? Please refer to JPush docs.

检查证书之后发现,描述性文件失效  iOS Provisioning Profiles (Development)

真机测试描述性文件

原因:该app的iOS App ID是在接推送SDK之前生成的,原先不具备推送功能,描述性文件也是原来生成的;创建推送证书之后,APP具备推送功能,但是描述性文件失效了,需要重新编辑一下,下载安装。

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第1张图片
开启推送

项目中选择开启Push Notifications,报错:

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第2张图片
项目中开启Push Notifications
iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第3张图片
描述性文件跟项目boundleId不匹配

原因:创建项目时,自动生成了bundled:ccc.CFJPush,但是修改时只修改了info.plist文件,导致项目的boudleId修改不彻底,在Build Settings里面搜索ccc.CFJPush,找到后修改成当前正确的bundled

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第4张图片
彻底修改bundled

接入SDK后发现,虽然能接收到推送的消息,但是走不到JPUSHRegisterDelegate的回调方法(支持iOS10以上的设备)因为Xcode7不支持iOS10新特性,测试设备系统是iOS11.2.1

适配iOS10新特性,需要UserNotifications.framework库,但是Xcode7项目中没有这个库,于是天真地从Xcode9项目下拷贝过来使用,但是发现不能用,会报错:

ld: unexpected token: !tapi-tbd-v2 file '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks//UserNotifications.framework/UserNotifications.tbd' for architecture arm64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

还是得升级Xcode,才能使用推送通知的iOS10新特性。

最后决定将Xcode7创建的项目挪到另一台电脑的Xcode9下运行。

运行报错:compiling IB documents for earlier than ios 7 is no longer supported

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第5张图片
从Xcode7移到Xcode9下报错

解决方案:

将所有的xib 和 storyboard文件逐个修改,选中View,builds for 改成 iOS7.1 and Later

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第6张图片
修改IB支持的设备系统

之后运行又遇到一个证书问题,但是项目中配置的证书是正确的:

/Users/用户名/Library/Developer/Xcode/DerivedData/CFJPush-gkytxdwouevpihashhckqnieucve/Build/Products/Debug-iphoneos/CFJPush.app: unknown error -1=ffffffffffffffff

Command /usr/bin/codesign failed with exit code 1

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第7张图片
证书问题

但是,电脑上原本就安装好了证书,重新将Xcode7电脑上导出的.p12证书,运行安装到钥匙串发现出错:

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第8张图片
证书无法导入钥匙串

解决方案:选中登录,将钥匙串锁定后,再打开。

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第9张图片
重新开启钥匙串

证书顺利导入到钥匙串,编译项目不再报错,Xcode9能顺利读取钥匙串中的证书,证书问题其实是个意外。

运行到真机又一个意外,Xcode9不支持iOS11.2.1(15C153):

This iPhone 6 is running iOS 11.2.1 (15C153), which may not be supported by this version of Xcode.

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第10张图片
Xcode9.0版本不支持iOS11.2.1系统

直接下载Xcode9.2下的iOS11.2(15C107):https://pan.baidu.com/s/1qZvudUc  密码:3122

打开应用程序-选中Xcode9-右键显示包内容-查找下列目录Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport,将新的测试包替换此目录下原来的测试包 - 重启Xcode9-成功运行到真机

解决JPush角标显示的问题

收到推送之后,角标默认显示1,不做处理情况下(即使已经读取推送内容)不会自动消失,不会自动增长

1. 让角标消失,可以在程序进入前台时处理:只需两行代码

找到AppDelegate.m文件中 - (void)applicationWillResignActive:(UIApplication *)application 方法

- (void)applicationWillResignActive:(UIApplication *)application {

//1---重置JPush服务器上面的badge值

//如果下次服务端推送badge传"+1",则会在你当时JPush服务器上该设备的badge值的基础上+1;

[JPUSHService setBadge:0];

//2---apple自己的接口,变更应用本地(icon)的badge值;

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

}

2. 让角标自增,在JPush服务器发送通知时,点开可选设置,注意 badge传"+1",默认状态下是1

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第11张图片
badge+1显示

JPush推送消息可以有“发送通知”和“自定义消息”两种形式

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第12张图片
发送通知
iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第13张图片
自定义消息

“发送通知”形式发送,当设备处于锁屏、App被杀死或者App处于后台时,都能正常收到推送的消息;当App处于前台时,虽然Jpush服务器显示收到消息,但消息不会以横幅、声音形式展示

如何在APP处于活跃状态时,让用户明确收到推送消息?如下两种方式

自己封装的收到远程消息后的处理逻辑

- (void)dealNotificationWithUserInfo:(NSDictionary *)userInfo{

self.notificationCount ++;

NSLog(@"self.notificationCount:%ld",self.notificationCount);

[UIApplication sharedApplication].applicationIconBadgeNumber = self.notificationCount;

//  远程推送,只能服务器来修改badge的值

// 在JPush平台发送通知时的可选设置中 +1,则正常显示,默认为1 上报badge

[JPUSHService setBadge:+1];

// ==============================================================

// 1 -- 应用处于前台收到推送的时候转成本地通知,效果跟其他状态下一致

// ==============================================================

if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {

UILocalNotification *notification = [[UILocalNotification alloc] init];

notification.userInfo = userInfo;

[[UIApplication sharedApplication] presentLocalNotificationNow:notification];

}

// ==============================================================

// 2 -- 在程序活跃状态下,程序设置弹出提示框,但推送不会以横幅、声音形式展示

// ==============================================================

//    if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {

//        NSString *body = userInfo[@"aps"][@"alert"][@"body"];

//    //    NSString *subtitle = userInfo[@"aps"][@"alert"][@"subtitle"];

//        NSString *title = userInfo[@"aps"][@"alert"][@"title"];

//        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title

//                                                            message:body

//                                                        delegate:nil

//                                                  cancelButtonTitle:@"OK"

//                                                  otherButtonTitles:nil];

//        [alertView show];

//    }

}

“自定义消息”形式发送,当App处于活跃状态(前台)时,设备能收到的远程消息,需要注册kJPFNetworkDidReceiveMessageNotification 通知

//  自己封装的注册通知方法,在初始化APNs和JPush之后调用即可

- (void)registNotification{

// 注册通知 收到消息(非APNS)

NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];

[defaultCenter addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];

}

// 自定义消息处理逻辑

- (void)networkDidReceiveMessage:(NSNotification *)notification {

NSDictionary * userInfo = [notification userInfo];

NSString *content = [userInfo valueForKey:@"content"];

NSDictionary *extras = [userInfo valueForKey:@"extras"];   //Jpush服务端传递的Extras附加字段,key是自己定义的

// 代码在程序活跃状态下,以弹框形式展示消息内容

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"前端自定义消息"

message:content

delegate:nil

cancelButtonTitle:@"OK"

otherButtonTitles:nil];

[alertView show];

}


下面说一下 cocos2-x-2.2.6项目,接入上述JPush sdk相关代码,使用Xcode9.0运行,遇到的问题 

Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState]

PID: 294, TID: 15778, Thread name: (none), Queue name: com.apple.root.default-qos.overcommit, QoS: 21

Backtrace:   .......

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第14张图片
线程问题

解决方案:选中Xcode-Product-Scheme-Edit Scheme-去掉 Main Thread Checker 前的对号

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第15张图片
去掉主线程检测

运行时,HttpClient.cpp文件中 curl_easy_cleanup(m_curl); 一行报错

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第16张图片
HttpClient.cpp文件报错

解决方案:修改HttpClient.cpp 和 HttpResponse.h文件中一些 int类型、int32_t类型 为long类型,具体修改内容如下:

HttpClient.cpp文件中

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第17张图片
97-100行
144行
iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第18张图片
332行
347行
357行
369行
381行

HttpResponse.h文件中

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第19张图片
113行
iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第20张图片
156行
178行

CCDataVisitor.h文件 报错:#include                   'string' file  not found

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第21张图片
引擎文件报错

原因C++与OC混编,自定义的JPushHelper类的头文件JPushHelper.h被AppController.mm引用,而JPushHelper.m文件后缀未修改。

解决方案:将JPushHelper.m改为JPushHelper.mm

报错:

duplicate symbol __sisHostDomains in:

    /Users/用户名/Desktop/cocos2d-x-2.2.6/projects/项目名/proj.ios/JPush/jpush-extension-ios-1.1.0.a(JPushExtensionSession.o)

    /Users/用户名/Desktop/cocos2d-x-2.2.6/projects/项目名/proj.ios/JPush/jcore-ios-1.1.7.a(JPUSHAddressController.o)

ld: 1 duplicate symbol for architecture armv7

clang: error: linker command failed with exit code 1 (use -v to see invocation)

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第22张图片
编译链接错误

开始以为跟上面的警告 xxx was built for newer iOS version(10.0)than being linked(7.0)有关

修改 项目名下  Deployment Target  6.0  为  8.0

和 cocos2dx.xcodeproj 下的 iOS Deployment Target iOS 6.0 为 iOS 8.0

无效!!!

并且会报警告:xxx was built for newer iOS version(10.0)than being linked(8.0)

上述错误跟警告无关。

后来发现JPush 版本更新文档描述中说,需要去掉-ObjC,由于原项目接其他SDK时有加-ObjC,并且之前接的其他的SDK已经不再使用。

解决方案:选中 Build Settings  ~ 搜索 Other Link Flags ~ 删掉-ObjC

在 Deployment Target 8.0下,使用usleep(1000)会报错:Use of undeclared identifier 'usleep'

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第23张图片
usleep(1000)

解决方案:引入头文件 #include "unistd.h"

运行安装到真机时报错:Could not launch “项目名”

                                          iPhone has denied the launch request.

iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1_第24张图片
Could not launch

解决方案:重启Xcode,运行

接收的远程推送消息中的应用名称显示错误

原因是之前将接入JPush的Demo安装到手机中,手机接收消息有缓存,到运行正式项目时,名称(ICON也可能错误)显示为原来的Demo中的名称

解决方案:重启手机,运行

你可能感兴趣的:(iOS Xcode7接入,Xcode9运行JPush极光推送遇到的问题 Command /usr/bin/codesign failed with exit code 1)