Ios 同一代码在另一台计算机上工作,但在我的计算机上不工作

Ios 同一代码在另一台计算机上工作,但在我的计算机上不工作,ios,xcode,watchkit,watchos,Ios,Xcode,Watchkit,Watchos,在我的apple watch应用程序上,我正在尝试用户通知。在模拟器上,此代码在另一台计算机上工作,但在我的计算机上不工作。我重新启动了我的电脑,更新了我的xcode(另一台电脑的xcode也是最新版本),我在我的电脑上尝试了不同的用户帐户。我能做什么?它可以是OSX版本吗?我必须检查什么 例如代码 接口控制器 - (IBAction)btnNotifiy { UNMutableNotificationContent* content = [[UNMutableNotificationC

在我的apple watch应用程序上,我正在尝试用户通知。在模拟器上,此代码在另一台计算机上工作,但在我的计算机上不工作。我重新启动了我的电脑,更新了我的xcode(另一台电脑的xcode也是最新版本),我在我的电脑上尝试了不同的用户帐户。我能做什么?它可以是OSX版本吗?我必须检查什么

例如代码

接口控制器

- (IBAction)btnNotifiy {
    UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init];
    content.title = [NSString localizedUserNotificationStringForKey:@"Wake up16!" arguments:nil];
    content.body = [NSString localizedUserNotificationStringForKey:@"Rise and shine! It's morning time!"
                                                         arguments:nil];
    content.sound = [UNNotificationSound defaultSound];



    // Configure the trigger for a 7am wakeup.
    NSDateComponents* date = [[NSDateComponents alloc] init];
    date.hour = 13;
    date.minute = 31;
    UNCalendarNotificationTrigger* trigger = [UNCalendarNotificationTrigger
                                              triggerWithDateMatchingComponents:date repeats:NO];

    // Create the request object.
    UNNotificationRequest* request = [UNNotificationRequest
                                      requestWithIdentifier:@"MorningAlarmTest41" content:content trigger:trigger];

    UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;

    [center getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> * _Nonnull requests) {
        NSLog(@"");
    }];

    [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
        if (error != nil) {
            NSLog(@"%@", error.localizedDescription);
        }
        NSLog(@"geldi");

    }];
    [center getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * _Nonnull notifications) {
        NSLog(@"");
    }];
}

-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {

    completionHandler();
}

-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
    NSLog(@"PUsh geldi");
}
-(iAction)b通知{
UNMutableNotificationContent*内容=[[UNMutableNotificationContent alloc]init];
content.title=[NSString LocalizedUserNotificationStringWorkey:@“Wake-up16!”参数:nil];
content.body=[NSString LocalizedUserNotificationStringWorkey:@“起床吧!早上到了!”
论点:无];
content.sound=[unnotificationsounddefaultsound];
//为7am唤醒配置触发器。
NSDateComponents*date=[[NSDateComponents alloc]init];
date.hour=13;
date.minute=31;
UNCalendarNotificationTrigger*触发器=[UNCalendarNotificationTrigger]
triggerWithDateMatchingComponents:日期重复:否];
//创建请求对象。
UNNotificationRequest*请求=[UNNotificationRequest]
requestWithIdentifier:@“MorningAlarmTest41”内容:内容触发器:触发器];
UNUserNotificationCenter*中心=[UNUserNotificationCenter currentNotificationCenter];
center.delegate=self;
[中心getPendingNotificationRequestsWithCompletionHandler:^(NSArray*_非空请求){
NSLog(@“);
}];
[center addNotificationRequest:request withCompletionHandler:^(N错误*_可为空错误){
如果(错误!=nil){
NSLog(@“%@”,错误。本地化描述);
}
NSLog(“geldi”);
}];
[中心getDeliveredNotificationsWithCompletionHandler:^(NSArray*\u非空通知){
NSLog(@“);
}];
}
-(void)userNotificationCenter:(UNUserNotificationCenter*)center未收到NotificationResponse:(UNNotificationResponse*)带有completionHandler的响应:(void(^)()completionHandler{
completionHandler();
}
-(void)userNotificationCenter:(UNUserNotificationCenter*)中心将使用completionHandler:(void(^)(UNNotificationPresentationOptions))completionHandler呈现通知:(UNNotification*)通知{
NSLog(@“推注凝胶”);
}
extensionelegate.m

- (void)handleBackgroundTasks:(NSSet<WKRefreshBackgroundTask *> *)backgroundTasks {
    // Sent when the system needs to launch the application in the background to process tasks. Tasks arrive in a set, so loop through and process each one.
    for (WKRefreshBackgroundTask * task in backgroundTasks) {
        // Check the Class of each task to decide how to process it
        if ([task isKindOfClass:[WKApplicationRefreshBackgroundTask class]]) {
            // Be sure to complete the background task once you’re done.
            WKApplicationRefreshBackgroundTask *backgroundTask = (WKApplicationRefreshBackgroundTask*)task;
            [backgroundTask setTaskCompleted];
        } else if ([task isKindOfClass:[WKSnapshotRefreshBackgroundTask class]]) {
            // Snapshot tasks have a unique completion call, make sure to set your expiration date
            WKSnapshotRefreshBackgroundTask *snapshotTask = (WKSnapshotRefreshBackgroundTask*)task;
            [snapshotTask setTaskCompletedWithDefaultStateRestored:YES estimatedSnapshotExpiration:[NSDate distantFuture] userInfo:nil];
        } else if ([task isKindOfClass:[WKWatchConnectivityRefreshBackgroundTask class]]) {
            // Be sure to complete the background task once you’re done.
            WKWatchConnectivityRefreshBackgroundTask *backgroundTask = (WKWatchConnectivityRefreshBackgroundTask*)task;
            [backgroundTask setTaskCompleted];
        } else if ([task isKindOfClass:[WKURLSessionRefreshBackgroundTask class]]) {
            // Be sure to complete the background task once you’re done.
            WKURLSessionRefreshBackgroundTask *backgroundTask = (WKURLSessionRefreshBackgroundTask*)task;
            [backgroundTask setTaskCompleted];
        } else {
            // make sure to complete unhandled task types
            [task setTaskCompleted];
        }
    }
}
-(无效)把手背景任务:(NSSet*)背景任务{
//当系统需要在后台启动应用程序来处理任务时发送。任务以集合的形式到达,因此循环并处理每个任务。
用于(WKRefreshBackgroundTask*背景任务中的任务){
//检查每个任务的类别以决定如何处理它
if([task isKindOfClass:[WKApplicationRefreshBackgroundTask类]]){
//完成后,确保完成后台任务。
WKApplicationRefreshBackgroundTask*backgroundTask=(WKApplicationRefreshBackgroundTask*)任务;
[背景任务setTaskCompleted];
}else if([task IsKindof类:[WKSnapshotRefreshBackgroundTask类]]){
//快照任务具有唯一的完成调用,请确保设置过期日期
WKSnapshotRefreshBackgroundTask*snapshotTask=(WKSnapshotRefreshBackgroundTask*)任务;
[snapshotTask setTaskCompletedWithDefaultStateRestored:YES estimatedSnapshotExpiration:[NSDate distantFuture]用户信息:nil];
}else if([task iskindof类:[WKWatchConnectivityRefreshBackgroundTask类]]){
//完成后,确保完成后台任务。
WKwatchConnectionyRefreshBackgroundTask*backgroundTask=(WKwatchConnectionyRefreshBackgroundTask*)任务;
[背景任务setTaskCompleted];
}else if([task isKindOfClass:[WKURLSessionRefreshBackgroundTask类]]){
//完成后,确保完成后台任务。
WKURLSessionRefreshBackgroundTask*backgroundTask=(WKURLSessionRefreshBackgroundTask*)任务;
[背景任务setTaskCompleted];
}否则{
//确保完成未处理的任务类型
[任务集任务已完成];
}
}
}

请不要重复发帖-尝试改进原始问题,例如包括代码、添加更多细节等。我删除了另一个我的错误。下次我会考虑的。Ern:你能告诉我在你的计算机上运行这个项目时你到底得到了什么错误吗?实际上我没有任何错误。我正在创建不可更改的通知内容,并将其交给联合国通知中心。当时间到了,我的屏幕上什么也没发生。我也添加了代码。但在另一台计算机的模拟器上使用相同的代码会显示通知屏幕。只需使用另一台计算机即可。这样你的代码就可以工作了。简单的