如何在 iPhone 中以编程方式设置锁屏、壁纸和铃声?

发布于 2024-10-08 09:09:23 字数 83 浏览 1 评论 0原文

在 iPhone 中,我们可以通过编程方式设置锁屏、壁纸和铃声吗?

如果,那么请告诉我如何设置它们?

In iPhone can we set the lock screen, wallpaper and ringtone programmatically?

If Yes, then please let me know how to set them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

网白 2024-10-15 09:09:23

这一切都可以轻松完成,但会被苹果拒绝。

可以通过更改com.apple.SpringBoard.plist(特别是ringtone键)来更改铃声。

以下代码可用于读取自定义铃声(由 iTunes 同步)的实际铃声标题。

NSMutableDictionary *custDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/private/var/mobile/Media/iTunes_Control/iTunes/Ringtones.plist"];
NSMutableDictionary *dictionary = [custDict objectForKey:@"Ringtones"];

NSArray *keys = [dictionary allKeys];
id key = [keys objectAtIndex:indexPath.row];
NSMutableDictionary *customRingtone = [dictionary objectForKey:key];
NSString *name = [customRingtone objectForKey:@"Name"];
cell.textLabel.text = name;

壁纸可以在以下位置覆盖:

NSString *homePath1 = @"/private/var/mobile/Library/SpringBoard/HomeBackground.jpg";
NSString *homePath2 = @"/private/var/mobile/Library/SpringBoard/HomeBackgroundPortrait.jpg";
NSString *lockPath1 = @"/private/var/mobile/Library/SpringBoard/LockBackground.jpg";
NSString *lockPath2 = @"/private/var/mobile/Library/SpringBoard/LockBackgroundPortrait.jpg";

这些示例用于我的 Cydia 应用程序之一。其实并没有什么更多的内容,但这些应该能让你朝着正确的方向前进。

This can all be done easily, but will be rejected by Apple.

The ringtone can be changed by altering com.apple.SpringBoard.plist, specifically the ringtone key.

The following code can be used to read the actual ringtone title of custom ringtones (synced by iTunes).

NSMutableDictionary *custDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/private/var/mobile/Media/iTunes_Control/iTunes/Ringtones.plist"];
NSMutableDictionary *dictionary = [custDict objectForKey:@"Ringtones"];

NSArray *keys = [dictionary allKeys];
id key = [keys objectAtIndex:indexPath.row];
NSMutableDictionary *customRingtone = [dictionary objectForKey:key];
NSString *name = [customRingtone objectForKey:@"Name"];
cell.textLabel.text = name;

The Wallpapers can be overwritten at:

NSString *homePath1 = @"/private/var/mobile/Library/SpringBoard/HomeBackground.jpg";
NSString *homePath2 = @"/private/var/mobile/Library/SpringBoard/HomeBackgroundPortrait.jpg";
NSString *lockPath1 = @"/private/var/mobile/Library/SpringBoard/LockBackground.jpg";
NSString *lockPath2 = @"/private/var/mobile/Library/SpringBoard/LockBackgroundPortrait.jpg";

These examples were used in one of my Cydia apps. Theres not really much more to them, but these should get you going in the right direction.

嘿咻 2024-10-15 09:09:23

由于 iOS 的更改,WrightsCS 的回答在某个时候停止工作。不幸的是,如果您想使用未记录的功能,您就必须忍受这一点。

如果您仍然需要执行此操作,仅适用于非 App Store 应用,此代码适用于 iOS 9.3。不过,它可能会在未来的任何 iOS 版本中停止工作。 (请参阅下面的评论:不再在 iOS 10 中工作)

#import "SBSUIWallpaperPreviewViewController.h"
#import <dlfcn.h>

// open the private framework dynamically
void *handle = dlopen("/System/Library/PrivateFrameworks/SpringBoardUIServices.framework/SpringBoardUIServices", RTLD_NOW);

UIImage *wallpaper = [UIImage imageNamed: @"background.jpg"];

Class sbClass = NSClassFromString(@"SBSUIWallpaperPreviewViewController");
// we create a view controller, but don't display it. 
//  just use it to load image and set wallpaper
SBSUIWallpaperPreviewViewController *controller = (SBSUIWallpaperPreviewViewController*)[[sbClass alloc] initWithImage: wallpaper];
[controller setWallpaperForLocations: 3];  // 3 -> set both for lock screen and home screen

dlclose(handle);

您需要将私有 API 标头添加到您的项目中。您通常可以通过一些搜索在网上找到这些, 例如,这里

在上面的示例中,使用参数 3 调用 [SBSUIWallpaperPreviewViewController setWallpaperForLocations:]:3 表示图像应用于两者锁定屏幕和主屏幕。 1 表示仅锁定屏幕。 2 仅表示主屏幕。


有关为什么我动态打开此框架的解释,请参阅我的相关答案

我没有关于铃声的答案。这确实应该是一个单独的问题:完全不同的 API 在工作。

The answer by WrightsCS stopped working at some point due to a change in iOS. Unfortunately, this is something you have to live with if you wish to use undocumented features.

If you still need to do this, for non-App Store apps only, this code works in iOS 9.3. It could stop working in any future iOS release, though. (see comment below: no longer working in iOS 10)

#import "SBSUIWallpaperPreviewViewController.h"
#import <dlfcn.h>

// open the private framework dynamically
void *handle = dlopen("/System/Library/PrivateFrameworks/SpringBoardUIServices.framework/SpringBoardUIServices", RTLD_NOW);

UIImage *wallpaper = [UIImage imageNamed: @"background.jpg"];

Class sbClass = NSClassFromString(@"SBSUIWallpaperPreviewViewController");
// we create a view controller, but don't display it. 
//  just use it to load image and set wallpaper
SBSUIWallpaperPreviewViewController *controller = (SBSUIWallpaperPreviewViewController*)[[sbClass alloc] initWithImage: wallpaper];
[controller setWallpaperForLocations: 3];  // 3 -> set both for lock screen and home screen

dlclose(handle);

You'll need to add the private API header to your project. You can usually find these online with a little searching, for example, here.

In the example above, [SBSUIWallpaperPreviewViewController setWallpaperForLocations:] is called with an argument of 3: 3 indicates the image should be used for both lock and home screens. 1 indicates Lock screen only. 2 indicates Home screen only.


For an explanation of why I open this framework up dynamically, see my related answer here.

I don't have an answer regarding ringtones. This really should be a separate question: completely different APIs at work.

遮了一弯 2024-10-15 09:09:23

如果可以的话使用私有 api
检查PLStaticWallpaperImageViewController

use private api if you can
check PLStaticWallpaperImageViewController

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文