【iOS打包報錯】Extension打包報錯armv7

/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)]

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容