/Users/tong/Desktop/wanshifu/Innovative/wanshifu-app-iOS/App.xcodeproj The linked framework 'Pods_GIONotificationServiceExtension.framework' is missing one or more architectures required by this target: armv7.
在 TARGETS ——> Build Settings-Excluded Architectures 中添加:

image.png
Extension——帶圖片推送步驟(前提:extension target證書一定要配置正確)
1、打adhoc包上傳到蒲公英
2、xcode運行項目到iPhone手機,獲取devicetoken,記錄devicetoken。
3、掃碼蒲公英下覆蓋安裝包
4、使用Knuff —— 推送工具,配置推送消息

image.png
{
"aps": {
"alert": {
"title": "最新資訊",
"body": "2017全國文明城市公布"
},
"sound": "default",
"badge": 1,
"mutable-content": 1
},
"image": "https://img1.gtimg.com/ninja/2/2017/05/ninja149447456097353.jpg"
}
5、收到推送消息,不能打開app,否則又需要重復2、3步驟

image.png
6、相關代碼
@interface NotificationService ()
@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
@property (nonatomic, strong) NSURLSession * session;
@end
@implementation NotificationService
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];
// 下載并關聯(lián)附件
NSString * urlString = self.bestAttemptContent.userInfo[@"image"];
[self loadAttachmentForUrlString:urlString
completionHandler: ^(UNNotificationAttachment *attachment) {
self.bestAttemptContent.attachments = [NSArray arrayWithObjects:attachment, nil];
[self contentComplete];
}];
}
- (void)serviceExtensionTimeWillExpire {
//這里進行操作超時后的補救···例如將圖片替換成默認圖片等等
self.bestAttemptContent.title = @"超時";
[self contentComplete];
}
- (void)contentComplete
{
[self.session invalidateAndCancel];
self.contentHandler(self.bestAttemptContent);
}
- (void)loadAttachmentForUrlString:(NSString *)urlString
completionHandler:(void (^)(UNNotificationAttachment *))completionHandler {
__block UNNotificationAttachment *attachment = nil;
__block NSURL *attachmentURL = [NSURL URLWithString:urlString];
//NSString *fileExt = [@"." stringByAppendingString:[urlString pathExtension]];
NSString *fileExt = [self fileExtensionForMediaType:@"image"];
if ([urlString containsString:@".jpg"] || [urlString containsString:@".png"]) {
fileExt = [@"." stringByAppendingString:[urlString pathExtension]];
}
//下載附件
_session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSURLSessionDownloadTask *task;
task = [_session downloadTaskWithURL:attachmentURL
completionHandler: ^(NSURL *temporaryFileLocation, NSURLResponse *response, NSError *error) {
if (error != nil) {
NSLog(@"%@", error.localizedDescription);
} else {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *localURL = [NSURL fileURLWithPath:[temporaryFileLocation.path
stringByAppendingString:fileExt]];
[fileManager moveItemAtURL:temporaryFileLocation
toURL:localURL
error:&error];
NSError *attachmentError = nil;
NSString * uuidString = [[NSUUID UUID] UUIDString];
//將附件信息進行打包
attachment = [UNNotificationAttachment attachmentWithIdentifier:uuidString
URL:localURL
options:nil
error:&attachmentError];
if (attachmentError) {
NSLog(@"%@", attachmentError.localizedDescription);
}
}
completionHandler(attachment);
}];
[task resume];
}
- (NSString *)fileExtensionForMediaType:(NSString *)type {
NSString *ext = type;
if ([type isEqualToString:@"image"]) {
ext = @"jpg";
}
if ([type isEqualToString:@"video"]) {
ext = @"mp4";
}
if ([type isEqualToString:@"audio"]) {
ext = @"mp3";
}
return [@"." stringByAppendingString:ext];
}
@end
RJNotificationDemo_iOS10
NotificationServiceExtension 與 NotificationContentExtension 的使用Demo【需要自己配置證書 】
僅做代碼展示,需要自己配置相關證書才能運行。
相關文章地址
Demo
[圖片上傳失敗...(image-56ed6f-1630058998315)]